CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011

    Exclamation Can I Still Get the Source Code?

    I have a program that I run in C# that goes to a website and in order to do its functions, I need to get the source code of the page.

    System.Net.WebClient webClient = new System.Net.WebClient();
    string strSource = webClient.DownloadString(URL);
    return strSource;
    Very recently, some of the pages return a [] character while others return the full source code of the page. When I go to the pages outside of my programming, the source code can be seen just as they should.

    Why would this be happening and is there a way around this?

  2. #2
    Join Date
    Mar 2004
    Prague, Czech Republic, EU

    Re: Can I Still Get the Source Code?

    I woudl try to download the data with WebClient.DownloadData() method and than labore with Encoding.(...).GetString() to get the source code of the page as string.
    From MSDN:
    Console.Write("\nPlease enter a URI (for example, http://www.contoso.com): ");
    string remoteUri = Console.ReadLine();
    // Create a new WebClient instance.
    WebClient myWebClient = new WebClient();
    // Download home page data.
    Console.WriteLine("Downloading " + remoteUri);                        
    // Download the Web resource and save it into a data buffer.
    byte[] myDataBuffer = myWebClient.DownloadData (remoteUri);
    // Display the downloaded data.
    string download = Encoding.ASCII.GetString(myDataBuffer);
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.