Sunday 9 October 2016

Read html from a Url

To read html from a url, you have to make HttpWebRequest.

First make HttpWebRequest and add url in it.


      HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("http://www.yourdomain.com/filename-1.html");      


Now Specify timeout and UserAgent

      httpRequest.Timeout = 10000;     // 10 secs
      httpRequest.UserAgent = "Code Sample Web Client";


Now get a response in HttpWebResponse and from HttpWebResponse you will get your html.

      HttpWebResponse webResponse = (HttpWebResponse)httpRequest.GetResponse();
      StreamReader responseStream = new StreamReader(webResponse.GetResponseStream());

      string FileMatter = responseStream.ReadToEnd();

In FileMatter variable you will get all html from given url.



Code
             HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("http://www.yourdomain.com/filename-1.html");  

            httpRequest.Timeout = 10000;     // 10 secs
            httpRequest.UserAgent = "Code Sample Web Client";

            HttpWebResponse webResponse = (HttpWebResponse)httpRequest.GetResponse();
            StreamReader responseStream = new StreamReader(webResponse.GetResponseStream());

            string FileMatter = responseStream.ReadToEnd();

Read html file from project folder

To read html from a file, first create a html file with some html in your project.






Write following code to read contents of a html file.



      System.IO.File.ReadAllText("http://www.yourdomain.com/3c-report-details.html");


Thursday 6 October 2016

Dhoni greatest innings vs pakistan


Keyword not supported: initial catalog

Introduction

In this In this article I will explain cause and resolution of Keyword not supported: initial catalog error

Cause

This error occurs when we are implement asp.net membership and error occurs in Global.asax file at the following line:
   WebSecurity.InitializeDatabaseConnection("Action", "Member", "MemberId", "Email", autoCreateTables:= True)
This error occurs when we have not specified provider name in connectionString.

Resolution

To resolve this error you need check your connectionString and add providername property in your connectionString.

Suppose you are trying to connect with Sql Server so you have to add providerName="System.Data.SqlClient"

Example

     <connectionStrings>
   <add name="con" connectionString="Data Source=ServerName;Initial Catalog=master;Integrated Security=SSPI;" providerName="System.Data.SqlClient"></add>
  </connectionStrings>