Recognizing url from window

Does anyone know how to strip a url from a Windows application?

I have an address http: //serverport/Page.I to remove this page from my windows application.

Best regards, Severe Suman

0


source to share


3 answers


It's not clear what you want to do with the page.

If you want to display it on a form, you can use a control WebBrowser

.



If you want to get the response and process it, use the class System.Net.WebClient

.

+3


source


If you want to load HTML or any file you can use the WebClient class.

Example:



    /// <summary>
    /// Downloads a file from the given location
    /// </summary>
    /// <param name="url">Location of the file</param>
    /// <param name="dest">The destination of the downloaded file</param>
    /// <returns>False if there was an error, else True</returns>
    public bool DownLoad(string url, string dest)
    {
        WebClient client = new WebClient();
        try
        {
            //Downloads the file from the given url to the given destination                
            client.DownloadFile(url, dest);
            return true;
        }
        catch (WebException)
        {
            // Handle exception
            return false;
        }
        catch (System.Security.SecurityException)
        {
            // Handle exception
            return false;
        }
        catch (Exception)
        {
            // Handle exception
            return false;
        }
    }

      

+1


source


I'm not sure what you are asking about, so I am just giving an answer for another way to interpret this question.

If you just want to start the default browser (to display local or online html tutorial, etc.), in windows (and probably similar on other OSs) you can use some sort of "runtime interface" to execute correctly formatted url as command, default browser usually starts:

According to this page, this code should launch the browser:

string targeturl= "http://stackoverflow.com";

try
    {
     System.Diagnostics.Process.Start(targeturl);
    }
catch
    ( 
     System.ComponentModel.Win32Exception noBrowser) 
    {
     if (noBrowser.ErrorCode==-2147467259)
      MessageBox.Show(noBrowser.Message);
    }
catch (System.Exception other)
    {
      MessageBox.Show(other.Message);
    }

      

(It looks pretty ugly with magic numbers for error codes, though ...)

0


source







All Articles