Getting SourceCode of Website

58 views Asked by At

I used the following code to get the SourceCode from a SharePoint 2010 site:

try {
    WebRequest req = HttpWebRequest.Create("myLink");
    req.Method = "GET";
    req.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

    string source = "";
    using (StreamReader reader = new StreamReader(req.GetResponse().GetResponseStream())) {
        source += reader.ReadToEnd();
    }
   }

From the source string i was able to search for keywords i was looking for on the website.

Now the SharePoint has been migrated to 2016 and i am not able anymore to view the specific content in the Source Code.

However it is posible to use for example the integrated web developer tool of chrome to view the structure of the site. Also my content i am looking for is visible in this case.

How is it possible to get this information programmatically using C#?

1

There are 1 answers

2
Thang Pham On

Try this:

    using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
    {
        client .Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
        string htmlCode = client.DownloadString("myLink");
        //...
    }