String Writer

my tech stuffs…

Archive for September 2011

Validate Web service in C#

leave a comment »

I’ve got many web services to read IMDB content. Some of them are failed to access while testing. So I needed to check whether they are really active before accessing them.

Here’s the code snippet to check any website/web services are active.


public bool IsWebServiceActive(string webServicePath)
{
  try
  {
     WebRequest request = WebRequest.Create(webServicePath);

     return ((HttpWebResponse)request.GetResponse()).StatusCode == HttpStatusCode.OK;;
  }
  catch (Exception ex)
  {
     Console.WriteLine(ex.Message);
     return false;
  }
}

Written by visvabalaji

September 16, 2011 at 12:23 pm

Posted in C#, SourceCode

Update registry files using C#

leave a comment »

When I was doing my IMDB app, I found some of the code snippets are frequently used for desktop applications. Here’s the one code sample.

I was having all my registry settings in .reg file instead of adding each entry through code. All we need to do is run this reg file through code.


string filePath = "IMDBSettings.reg";
.
.
.
Process.Start("regedit.exe", "/s " + filePath).WaitForExit();

Written by visvabalaji

September 16, 2011 at 12:04 pm

Posted in C#, SourceCode

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: