0

This is what I am trying to do.

  1. Windows Form App loads with web browser
  2. Goes to a certain link
  3. Checks to see if the url bar is empty, if not it takes the current url and writes to a string and then navigates to some other url.

I keep getting Cannot implicitly convert type 'System.Uri' to 'string' and I have tried a few things but can't get my head around it.

string url;

try
{
    if (webBrowser1.Url != null)
    {
        // url = webBrowser1.Url;

        MessageBox.Show("Success!");

    }
    else
    {
        MessageBox.Show(":(!");
    }
}
catch
{
     MessageBox.Show("Something Screwed Up");
}

Now at this point I get :( when I comment out the error. This is on form1.cs - should I be doing this on program.cs? It seems like the object may not be created a the point when I check but I have no idea. By default the form loads with a URL pre-loaded.

1 Answer 1

4

webBrowser1.Url is URI object

url is String object

it tells you those are diffrent types and there no implicit convertion

url = webBrowser1.Url.ToString();

see great article:

http://msdn.microsoft.com/en-us/library/ms173105.aspx

Sign up to request clarification or add additional context in comments.

2 Comments

@ChrisEather the proper way to say thank you in StackOverflow is to "1 up" an answer or a comment. also consider to check the answer that helped you the most as Accepted answer. in order to tell the rest of the community that this answer solved the problem at the question. choosing approved answer will increase your accept rating and it will make users more inclined to help you.
@Chris Eather you are very welcome. I advice you to read well exceptions and try searching them online if you would have searched "Cannot implicitly convert type 'System.Uri' to 'string'" you would have found the answer. if this would have failed you would surely have found : "Cannot implicitly convert type"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.