<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-1895044007297610042</id><updated>2009-11-09T06:22:02.065-08:00</updated><title type='text'>DOTNET  BLOG</title><subtitle type='html'>This blog is meant to post the articles on the topics which i come accross as a part my work.The main idea is share the ideas which i came to know with lot of R&amp;amp;D work.Comments from the readers are most expected so that i can improove my postings.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-4419727561437303923</id><published>2009-01-29T21:57:00.000-08:00</published><updated>2009-01-30T01:24:54.389-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Import Internet Explorer Favorites with C# and Javascript'/><title type='text'>How to  access Internet Explorer Favourites programatically through C# code &amp; javascript code ??</title><content type='html'>This article is about how to access Internet Explorer Favorites programatically from C#  &amp;amp; javascript code.When ever a Favorite is added in IE , it is stored as a *.url file in "Favorites" foldler of "Documents &amp;amp; Settings" of Windows drive.This location depends on O/S , but it can be accessed through environment variables.&lt;br /&gt;&lt;u&gt;&lt;strong&gt;From C#:&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;Create a console application in visual studio &amp;amp; copy the following code in main method.&lt;br /&gt;&lt;span style="color:#33cc00;"&gt;//Code &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;GetFavoriteFiles(Environment.GetFolderPath(Environment.SpecialFolder.Favorites));&lt;br /&gt;foreach (string s in favFiles)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(s);&lt;br /&gt;}&lt;br /&gt;Console.Read();&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#33cc00;"&gt;//&lt;/span&gt;&lt;br /&gt;in the above code &lt;strong&gt;'GetFavoriteFiles("..")&lt;/strong&gt;' is method which gets the favorite files in that folder &amp;amp; in sub folders if any. The method looks like this&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#33cc00;"&gt;//Code&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;static List&lt;string&gt; favFiles = new List&lt;string&gt;();&lt;br /&gt;private static void GetFavoriteFiles(string folder)&lt;br /&gt;{&lt;br /&gt;   string[] favs = Directory.GetFiles(folder);&lt;br /&gt;   favFiles.AddRange(favs);&lt;br /&gt;   string[] folders = Directory.GetDirectories(folder);&lt;br /&gt;   if (folders != null)&lt;br /&gt;  {&lt;br /&gt;       foreach (string s in folders)&lt;br /&gt;      {&lt;br /&gt;          GetFavoriteFiles(s);&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#33cc00;"&gt;//&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;The above code gets all the IE favorites in form of *.url files.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#333333;"&gt;&lt;u&gt;&lt;strong&gt;JavaScript Code :&lt;/strong&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;&lt;span style="color:#333333;"&gt;&lt;/span&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;var i=0;   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;var favString="";  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;var fso;        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;function Import()   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;{        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;    try        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;    {            &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;       fso=new ActiveXObject("Scripting.FileSystemObject");         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;        if(fso !=null )            &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;            {                    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;            //Create windows script shell object to access Favorites folder in user system.                  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;             var object=new ActiveXObject("WScript.Shell");              &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;             var favfolderName=object.SpecialFolders("Favorites")    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;             if(favString=="")   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;             {                     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;                      GetFavourites(favfolderName);     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;             }                         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;            }               .&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;      }        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;     catch(err)     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;     {            &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;         alert("Security settings to be modified in your browser ")       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;      }  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt; }    &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  //Recursive method which retrieves Favourite Name &amp;amp; URL for a given folder &amp;amp; subfolders.     &lt;span style="color:#ff0000;"&gt;function GetFavourites(Folder)    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;{         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;      var FavFolder=fso.GetFolder(Folder);    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;     //Gets Favourite Names &amp;amp; URL's for given folder.        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;     var files=new Enumerator(FavFolder.Files)    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;     for(; !files.atEnd() ;files.moveNext())       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;     {           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;          var fil=files.item();  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;          if(fil.Type=="Internet Shortcut")    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;          {&lt;br /&gt;                var textReader=fso.OpenTextFile(fil.Path,1,false,-2)         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;               var favtext=textReader.ReadAll() &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;               var start=favtext.indexOf("URL",16)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;               var stop=favtext.indexOf("\n",start) &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;               favString+=fil.Name.replace(/.url/,"");&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;                favString+=":URL:";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;            //to separate favourite name &amp;amp; favorite URL    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;                favString+=favtext.substring(start+4,stop-1); &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;               favString+=":NEXT:"; //to separate favorites. &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;               i++;            &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;           }       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;      }       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;         //Checks any subfolder exists     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;        var subfolders=new Enumerator(FavFolder.SubFolders)   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;        for(; !subfolders.atEnd() ;subfolders.moveNext())      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;        {           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;          var folder=subfolders.item(); &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;           GetFavourites(folder.Path); &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;         } &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;The above javascript code also extracts the URL of the favorite.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-4419727561437303923?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/4419727561437303923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=4419727561437303923' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/4419727561437303923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/4419727561437303923'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2009/01/how-to-access-internet-explorer.html' title='How to  access Internet Explorer Favourites programatically through C# code &amp; javascript code ??'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-6602227717420958331</id><published>2008-10-25T04:23:00.000-07:00</published><updated>2008-10-25T05:21:03.405-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='using statement in C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Best practice for using IDisposable object in C#'/><title type='text'>Some points on using statement in C# !</title><content type='html'>* using Statement provides standard way of using objects which implements &lt;span style="font-weight: bold;"&gt;IDisposable&lt;/span&gt; interface.&lt;br /&gt;*generally &lt;span style="font-weight: bold;"&gt;IDisposable&lt;/span&gt; objects are those wraps unmanaged resources in them &amp;amp; hence &lt;span style="font-weight: bold;"&gt;Dispose() &lt;/span&gt;method can be called to release unmanahed resource.&lt;br /&gt;*If &lt;span style="font-weight: bold;"&gt;IDisposable&lt;/span&gt; object  is declared &amp;amp; instantiated in using statement then &lt;span style="font-weight: bold;"&gt;Dispose()&lt;/span&gt; method will be automatically called while control leaving the using block.&lt;br /&gt;*The&lt;span style="font-weight: bold;"&gt; IDisposable&lt;/span&gt; can be declared &amp;amp; instantiated as other objects noramally &amp;amp; call the &lt;span style="font-weight: bold;"&gt;Dispose()&lt;/span&gt; method to release unmanaged resources.&lt;br /&gt;*But putting it in using statement ensures that the object is disposed even when any exception occured while calling methods on object.&lt;br /&gt;*This is equivalent to intantiating &lt;span style="font-weight: bold;"&gt;IDisposable&lt;/span&gt; object in &lt;span style="font-weight: bold;"&gt;try/ catch&lt;/span&gt; block &amp;amp; calling &lt;span style="font-weight: bold;"&gt;Dispose()&lt;/span&gt; in finally  block.&lt;br /&gt;*With in the using block the object is readonly , it cant reassigned.&lt;br /&gt;&lt;br /&gt;Below code shows how to use &lt;span style="font-weight: bold;"&gt;IDisposable&lt;/span&gt; objects&lt;br /&gt;&lt;br /&gt;//&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;using (StreamReader streamreader = File.OpenText(@"FilePath"))&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;            {&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                string filetext = streamreader.ReadToEnd();&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;            }&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-6602227717420958331?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/6602227717420958331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=6602227717420958331' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/6602227717420958331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/6602227717420958331'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/10/some-points-on-using-statement-in-c.html' title='Some points on using statement in C# !'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-671077504471827030</id><published>2008-10-24T23:07:00.000-07:00</published><updated>2008-10-24T23:38:04.495-07:00</updated><title type='text'>How to get HTML content of a web page for a given URL programatically with c# ?</title><content type='html'>This article shows how to grab the HTML content of a given url programatically with C#.DotNet Framework provides different classes to send http web request programatically which are under namespaec '&lt;span style="font-weight: bold;" class="selflink"&gt;System.Net&lt;/span&gt;'.For the current implementation i'm using types '&lt;span style="font-weight: bold;"&gt;HttpWebRequest&lt;/span&gt;' to send hhtp request and &lt;span style="font-weight: bold;"&gt;'HttpWebResponse&lt;/span&gt;' to  capture the response send by web server.&lt;br /&gt;The code looks like this&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;static void Main(string[] args)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;          &lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;            string html;&lt;br /&gt;&lt;/span&gt;  &lt;span style="color: rgb(153, 0, 0);"&gt;                   HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://google.com");&lt;br /&gt;&lt;/span&gt; &lt;span style="color: rgb(153, 0, 0);"&gt;                   try&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                   {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                          HttpWebResponse res =(HttpWebResponse)req.GetResponse();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                           if (res != null)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                          {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                if (res.StatusCode == HttpStatusCode.OK)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                 {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                       Stream stream = res.GetResponseStream();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                        using (StreamReader reader = new StreamReader(stream))&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                       {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                           html = reader.ReadToEnd();&lt;br /&gt;&lt;/span&gt; &lt;span style="color: rgb(153, 0, 0);"&gt;                                      }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                     Console.Write(html);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;                                    Console.Read();&lt;br /&gt;&lt;/span&gt;  &lt;span style="color: rgb(153, 0, 0);"&gt;                             }&lt;br /&gt;&lt;/span&gt;                             &lt;span style="color: rgb(153, 0, 0);"&gt; res.Close();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;         }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;              }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;               catch { }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(153, 0, 0);"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Both the &lt;span style="font-weight: bold;"&gt;HttpWebRequest&lt;/span&gt; &amp;amp; &lt;span style="font-weight: bold;"&gt;HttpWebResponse&lt;/span&gt; objects doesnt support any constructors.The Type &lt;span style="font-weight: bold;"&gt;WebRequest&lt;/span&gt; supports static method called &lt;span style="font-weight: bold;"&gt;Create()&lt;/span&gt; which takes URL of the web page as parameter &amp;amp; returns '&lt;span style="font-weight: bold;"&gt;WebRequest&lt;/span&gt;' object which can be casted to 'HttpWebRequest'.&lt;br /&gt;Similarly &lt;span style="font-weight: bold;"&gt;HttpWebRequest&lt;/span&gt; object supports method &lt;span style="font-weight: bold;"&gt;GetResponse()&lt;/span&gt; which returns WebResponse object which can be casted into &lt;span style="font-weight: bold;"&gt;HttpWebResponse&lt;/span&gt;.The response of the internet resource can be accessed from &lt;span style="font-weight: bold;"&gt;HttpWebResponse &lt;/span&gt;object by calling '&lt;span style="font-weight: bold;"&gt;GetResponseStream()&lt;/span&gt;'  which returns a stream.&lt;br /&gt;If the method of the http request to internet source is &lt;span style="font-weight: bold;"&gt;POST&lt;/span&gt;  &amp;amp; it is having any &lt;span style="font-weight: bold;"&gt;PostData&lt;/span&gt; which to be attached to http request can be sent by attaching it to HttpRequest Stream which can be accessed by calling the method &lt;span style="font-weight: bold;"&gt;GetRequestStream()&lt;/span&gt; of &lt;span style="font-weight: bold;"&gt;HttpWebRequest&lt;/span&gt; object.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-671077504471827030?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/671077504471827030/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=671077504471827030' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/671077504471827030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/671077504471827030'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/10/how-to-get-html-content-of-web-page-for.html' title='How to get HTML content of a web page for a given URL programatically with c# ?'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-1702810593980779025</id><published>2008-10-18T00:07:00.000-07:00</published><updated>2008-10-18T00:50:48.717-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='&apos;System.IO.Compression&apos;'/><category scheme='http://www.blogger.com/atom/ns#' term='Compress and Decompress String in C#'/><title type='text'>How to Compress  &amp; Decompress Strings in C# ?</title><content type='html'>This article show how to compress strings in C#. Dotnet Framework provides classes to compress the streams which can be found in &lt;strong&gt;&lt;span style="color:#006600;"&gt;'System.IO.Compression'&lt;/span&gt;&lt;/strong&gt;.The class i'm going to use is &lt;span style="color:#006600;"&gt;'&lt;strong&gt;GZipStream&lt;/strong&gt;&lt;/span&gt;'.Basically this class compresses streams , one can be use this class to compress even files.But here i'm using to compress string.&lt;br /&gt;&lt;br /&gt;  As i said class '&lt;span style="color:#006600;"&gt;&lt;strong&gt;GZipStream&lt;/strong&gt;'&lt;/span&gt; provides methods to compress streams, i'm converting my string to stream first then compressing the resulting stream.&lt;br /&gt;Code looks like this&lt;br /&gt;//&lt;br /&gt;For Compression&lt;br /&gt;&lt;span style="color:#990000;"&gt;public string Compress(string text)&lt;br /&gt;{&lt;br /&gt;      byte[] buffer = Encoding.UTF8.GetBytes(text);&lt;br /&gt;        MemoryStream ms = new MemoryStream();&lt;br /&gt;        using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))&lt;br /&gt;       {&lt;br /&gt;            zip.Write(buffer, 0, buffer.Length);&lt;br /&gt;       }&lt;br /&gt;      ms.Position = 0;&lt;br /&gt;      byte[] compressed = new byte[ms.Length];&lt;br /&gt;     ms.Read(compressed, 0, compressed.Length);&lt;br /&gt;    byte[] gzBuffer = new byte[compressed.Length + 4];&lt;br /&gt;    System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);&lt;br /&gt;    System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);&lt;br /&gt;    return Convert.ToBase64String(gzBuffer);&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For decompression&lt;br /&gt;&lt;span style="color:#990000;"&gt;public string Decompress(string compressedText)&lt;br /&gt;{&lt;br /&gt;           byte[] gzBuffer = Convert.FromBase64String(compressedText);&lt;br /&gt;         using (MemoryStream ms = new MemoryStream())&lt;br /&gt;        {&lt;br /&gt;            int msgLength = BitConverter.ToInt32(gzBuffer, 0);&lt;br /&gt;            ms.Write(gzBuffer, 4, gzBuffer.Length - 4);&lt;br /&gt;            byte[] buffer = new byte[msgLength];&lt;br /&gt;            ms.Position = 0;&lt;br /&gt;            using (GZipStream zip = new GZipStream(ms, CompressionMode.Decompress))&lt;br /&gt;             {&lt;br /&gt;                zip.Read(buffer, 0, buffer.Length);&lt;br /&gt;             }&lt;br /&gt;          return Encoding.UTF8.GetString(buffer);&lt;br /&gt;        }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;&lt;strong&gt;Note:&lt;/strong&gt;The compression rate will be higher for larger strings.As the number character in string increases the rate of compression will be increased.&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-1702810593980779025?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/1702810593980779025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=1702810593980779025' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/1702810593980779025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/1702810593980779025'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/10/how-to-compress-decompress-strings-in-c.html' title='How to Compress  &amp; Decompress Strings in C# ?'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-9201908177250437289</id><published>2008-09-15T05:56:00.000-07:00</published><updated>2008-09-15T06:18:35.020-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web service behaviour'/><category scheme='http://www.blogger.com/atom/ns#' term='DHTML Behaviours'/><title type='text'>Call WebService from javascript</title><content type='html'>&lt;span class="Apple-style-span"  style=" ;font-family:'Times New Roman';"&gt;&lt;div style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; width: auto; font: normal normal normal 100%/normal Georgia, serif; text-align: left; "&gt;&lt;div&gt;This article shows how to call a web service from javascript.To understand this article better litle knowledge of following topics is required.&lt;br /&gt;&lt;u&gt;1)DHTML Behaviours :&lt;/u&gt; DHTML behaviours introduced with Microsoft Internet Explore (5.5).They are components which encapsulates specfic functionaly on a page. For more info check &lt;a href="http://msdn.microsoft.com/en-us/library/ms531079.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms531079.aspx&lt;/a&gt; .&lt;br /&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;u&gt;2)Web Services:&lt;/u&gt; Web services are reusable components shared over net which can used by applications irrespective of platform &amp;amp; vendor.To understand the article one doesnt need to create a web service.Only thing is a web service is needed with some functionality.&lt;br /&gt;&lt;br /&gt;To call web service we need a 'Web Service' DHTML behaviour.This behaviour provides methods like 'useService' &amp;amp; 'callService' to call web service.&lt;br /&gt;&lt;br /&gt;For example say web service has a web method something like this ...&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;[WebMethod]&lt;br /&gt;public string DemoMethod(string str)&lt;br /&gt;{&lt;br /&gt;return "From Web Service" + str;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;//The method looks simple, takes a string as parameter &amp;amp; returns another string.&lt;br /&gt;for instance say URl of the service is 'http://localhost/Service1.asmx' .&lt;br /&gt;Now you hav a webservice which to be called in javascript.To call from javascript follow the following.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;As i said before 'Web Service behaviour ' is needed to call the web service.This behaviour to be attached to a HTML Element on a web page.For instance say 'div' element.The mark up looks like this.&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt; id="Service1" style="BEHAVIOR: url(webservice.htc)" onresult="processResult()"&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;In the above markup id 'Service1' is required to call the methods 'useService' &amp;amp; 'callService' methods.Once behaviour is attached to the html elements all the members supported by the behaviour can be accessed throught the id of that element.&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;*Then style attribute is the where actually behaviour is attached to the element.For the current requirement we need web service behaviour ie 'webservice.htc '.For the above code should properly 'webservice.htc' file to be placed in the folder in which your web page resides.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;The 'webservice.htc' file can be downloaded from MSDN website.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;*Then 'onresult' attribute specifies the javascript method to be called after execution of the method is completed.In this method 'result' object preovides the result returned by web service.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;After attaching the web service behaviour to html element on web page , the next step is to call methods of web service behaviour.The code looks like this ...&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color:#ff0000;"&gt;function init()&lt;br /&gt;{&lt;/span&gt;&lt;span style="color:#33cc00;"&gt;//This method is called to map the web service url to friendly name which can be used later call methods in actual web service (*.asmx file)&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color:#33cc00;"&gt;//first parameter to the method is actual url of web service.second parameter specifies the friendly name to this url which can be used as reference to url.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color:#33cc00;"&gt;//note that id given to the html element is used to&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Service1.useService("&lt;/span&gt;&lt;a href="http://localhost:3169/Service1.asmx"&gt;&lt;span style="color:#ff0000;"&gt;http://localhost/Service1.asmx&lt;/span&gt;&lt;/a&gt;&lt;span style="color:#ff0000;"&gt;?WSDL","myService")&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color:#009900;"&gt;//This method calls the actual method in web service.The first is the name of the method in web service.the second parameter is parameter to web method.Call to these methods are asyncronuos.So when web method execution is completed then the method specified in 'onresult' attribute is called.In this method 'result' object provides the result sent by web service.&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Service1.myService.callService("HelloWorld","From javascript ")&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;//Result method&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color:#ff0000;"&gt;function processResult(result)&lt;br /&gt;{&lt;br /&gt;if(result.error)&lt;br /&gt;{&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;span style="color:#33cc00;"&gt;//Checks for any error returned from web method&lt;br /&gt;&lt;/span&gt;alert(result.errorDetail.string)&lt;br /&gt;alert(result.errorDetail.code)&lt;br /&gt;alert(result.errorDetail.raw)&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;alert(result.value);&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Now the init() method to be called in onload() event of the body.like&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color:#ff0000;"&gt;&lt;br /&gt;&lt; onload="init()"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;This means that web service is called when page is loaded.We can also call the web service on other events like button click.At that time 'callservice' method to be called in button click event.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;But 'useservice' method to be called on 'onload' event of 'body'.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;This article uses a simple web method which takes string as parameter &amp;amp; another string , but it can be any.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;For more info on webservice behaviour check out&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms531032.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms531032.aspx&lt;/a&gt; &amp;amp;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms531033(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/ms531033(VS.85).aspx&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-9201908177250437289?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/9201908177250437289/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=9201908177250437289' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/9201908177250437289'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/9201908177250437289'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/09/call-webservice-from-javascript.html' title='Call WebService from javascript'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-2065846768968813153</id><published>2008-08-23T02:15:00.000-07:00</published><updated>2008-08-23T02:38:03.765-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programatically run applications'/><title type='text'>How to run applications under system control programatically through C#</title><content type='html'>This Article describes how to run applications under control  of o/s programatically with C#.For example one have to open notepad programatically or Internet Explorer or any other *.EXE application installed in system.&lt;br /&gt;.Net framework provides &lt;strong&gt;'System.Diagnostics' &lt;/strong&gt;namespace which provides types to interact with process under o/s.For our current requirement we need '&lt;strong&gt;Process&lt;/strong&gt;' class under &lt;strong&gt;'System.Diagnostics'&lt;/strong&gt;  namespace.&lt;strong&gt;'Process&lt;/strong&gt;' provides static &amp;amp; instance methods to run an *.EXE application.Below i presented code to open notepad programatically.&lt;br /&gt;&lt;span style="color:#009900;"&gt;//code&lt;/span&gt;&lt;br /&gt;Process.Start("NOTEPAD");&lt;br /&gt;&lt;br /&gt;the above piece of code opens the notepad.&lt;br /&gt;Its also possible to send parameters to &lt;strong&gt;Process &lt;/strong&gt;with  the help of '&lt;strong&gt;ProcessStartInfo&lt;/strong&gt;' class.&lt;br /&gt;For example if one wants to open internetExplorer &amp;amp; navigate to Google home page programatically , it can be done with following piece of code.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#33cc00;"&gt;//code&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;ProcessStartInfo startinfo = new ProcessStartInfo();&lt;br /&gt;startinfo.FileName = "IEXPLORE";&lt;br /&gt;startinfo.Arguments = "Http://google.com";&lt;br /&gt;Process.Start(startinfo);&lt;br /&gt;&lt;br /&gt;When you run above code , a new IE window will be opened with Google home page.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-2065846768968813153?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/2065846768968813153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=2065846768968813153' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/2065846768968813153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/2065846768968813153'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/08/how-to-run-applications-under-system.html' title='How to run applications under system control programatically through C#'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-3064184981811333977</id><published>2008-08-23T00:26:00.000-07:00</published><updated>2008-08-23T02:13:16.834-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Add ContextMenu Item to IE'/><category scheme='http://www.blogger.com/atom/ns#' term='Registry Modifications With C#'/><title type='text'>How to Add Context Menu Item to Internet Explorer Browser.</title><content type='html'>&lt;span style="font-family:arial;"&gt;This&lt;/span&gt; article describes about how to add custom context menu item to Internet Explorer Browser.This essentialy involves registry modifications.This can be done either manually or programatically.Manually means opening system registry &amp;amp; editing manually.Programatically in the sense writing code to edit registry.For programatic editing i'l present C# coding.&lt;br /&gt;&lt;u&gt;Context Menu:&lt;/u&gt;&lt;br /&gt;Context menu is menu which will be opened on mouse right buttom click on a window.&lt;br /&gt;Note:To understand this article better a basic understanding of system registry is essential.&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Manul Way:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;Internet Explorer has its own default context menu.If one wants to add custom menu item to this default menu,microsoft is providing a way to do this.This typically requires 'System registry' modifications.To add a context item open system registry.For this follow below navigation.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Start --&gt; Run ---&gt;regedit&lt;/span&gt;&lt;br /&gt;Then registry will be opened.In registry navigate to following path &lt;span style="color:#cc0000;"&gt;'HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt'&lt;/span&gt;&lt;br /&gt;Under 'MenuExt' key add a new key.The name of this key will be the name of menu item in Internet Explorer.For instance say 'MyMenuItem'.Once key is added a default string value is added to this key.The Value of the this default string should be the path of the Script file which will be executed when 'MyMenuItem' is clicked.For instance say 'C:\MyMenuItem.htm'This may be .js file or .htm file.Once this is done the menu item  will appear in Internet Explorer Context Menu.&lt;br /&gt;                Now 'MyMenuItem' item will be appear in IE context menu.One can perform what ever the action needed by adding appropriate script in sript file.The window can be accessed from the script  as follows.&lt;br /&gt;//gets the window&lt;br /&gt;  var window=external.menuArguments ;&lt;br /&gt;//to get the document object&lt;br /&gt;  var doc=window.document ;&lt;br /&gt; //perform action  .....&lt;br /&gt;&lt;br /&gt;This is how a context menu item can be added to IE manually.If context menu item to work for specific items like Selected text,image or links, this can be done by specifying 'Context' value for 'MyMenuItem' key in registry.&lt;br /&gt;To Add content specific context menu item to IE, Add 'DWORD'  type value to 'MyMenuItem' key &amp;amp; name it 'Context'.The value of the 'Context' decides to which content the menu item is available.&lt;br /&gt;The valid values of 'Context' &amp;amp; their corresponding contents are given below.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;0x1 (Hex) -- this default&lt;/li&gt;&lt;li&gt;0x2 (hex)-- for images (means this context menu item available for only images )&lt;/li&gt;&lt;li&gt;0x4    "       ---for controls&lt;/li&gt;&lt;li&gt;0x8     "    --- for tables&lt;/li&gt;&lt;li&gt;0x10        ---for selected text&lt;/li&gt;&lt;li&gt;0x20        ---for Anchors(links)&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Note:before editing Registry ensure that Registry back up is taken.&lt;/p&gt;&lt;p&gt;For More Info about Customising IE Check &lt;a href="http://msdn.microsoft.com/en-us/library/bb735853(VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/bb735853(VS.85).aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;u&gt;Programatic Way:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;.net framework provides built in API to work with system registry.&lt;/p&gt;&lt;p&gt;Note:Make sure that namespace 'Microsoft.Win32' is accessible to your code&lt;/p&gt;&lt;p&gt;RegistryKey registryKey;&lt;br /&gt;registryKey = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Internet Explorer\MenuExt");&lt;/p&gt;&lt;p&gt;//Adding registry key 'MyMenuItem'&lt;br /&gt;RegistryKey addSourceKey = registryKey.CreateSubKey("MyMenuItem");&lt;/p&gt;&lt;p&gt;//Set Default string value to Path of the script file&lt;br /&gt;addSourceKey.SetValue("", "C:\\MyMenuItem.htm");&lt;br /&gt;addSourceKey.Close();&lt;br /&gt;registryKey.Close();&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-3064184981811333977?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/3064184981811333977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=3064184981811333977' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/3064184981811333977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/3064184981811333977'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/08/how-to-add-context-menu-item-to.html' title='How to Add Context Menu Item to Internet Explorer Browser.'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-8229162463307160163</id><published>2008-07-28T22:17:00.000-07:00</published><updated>2008-07-28T23:34:05.641-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='webbrowser control'/><category scheme='http://www.blogger.com/atom/ns#' term='Httpstatus codes'/><title type='text'>Capturing HTTP Status codes with 'WebBrowserControl'</title><content type='html'>WebBrowser is a winndows forms control which allows you to add web browsing capabilities to windows application developed with .net technology(i.e C#.net or vb.net).This control acts in a similar way to &lt;strong&gt;Internet Explorer&lt;/strong&gt; Browser.Its supports methods &amp;amp; events to navigate to url ,properties to work with &lt;strong&gt;HTML Document Object Model(DOM)&lt;/strong&gt; etc.But it doesn't allow to capture directly some things programatically,for example HTTP status codes.If the requested web page is not found then HTTP Status code '404' is shown on web browser,but with if u want capture this status code programatically,its not straight farward. Actually &lt;strong&gt;WebBrowser &lt;/strong&gt;windows forms control is wrapper WebBrowser ActivexControl in '&lt;strong&gt;Microsoft Internet Control(SHDocVw.dll)&lt;/strong&gt;'&lt;strong&gt; &lt;/strong&gt;library which is a COM component.WebBrowser windows forms control doesnt support all the events supported by Activex Control (Web Browser).Activex Control supports '&lt;strong&gt;NavigateError&lt;/strong&gt;' event which will be raised when any error occured while navigating to url.By handling this event one can get HTTP Status codes for a requested url.&lt;br /&gt;To capture '&lt;strong&gt;NavigateError&lt;/strong&gt;' with windows forms &lt;strong&gt;'Web Browser&lt;/strong&gt;' control a work around is there.Its possible to cast windows forms 'Web Browser' into Activex control.The under lying ActiveXControl of windows forms WebBrowser control can be accessed through a property called 'ActiveXInstance'.The code looks like this&lt;br /&gt;&lt;br /&gt;Code :&lt;br /&gt;Following library to added to the project.&lt;br /&gt;* 'Microsoft Internet Control(SHDocVw.dll) which can be found under COM tab of Add Reference window.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();&lt;br /&gt;System.Windows.Forms.WebBrowserBase wb1;&lt;br /&gt;SHDocVw.WebBrowser wb2 = (SHDocVw.WebBrowser)wb.ActiveXInstance;&lt;br /&gt;wb2.NavigateError += new DWebBrowserEvents2_NavigateErrorEventHandlerwb2_NavigateError);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#33cc00;"&gt;//event handler for NavigateError event&lt;br /&gt;&lt;/span&gt;void wb2_NavigateError(object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel)&lt;br /&gt;{&lt;br /&gt;throw new NotImplementedException();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;If any error occured while navigating to URL the 'NavigateError' will be raised.The 'StatusCode'&lt;br /&gt;parameter of the event handler gives the HTTP Status code.&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Note:Not all the HTTP status codes can be get through this approach.As the event is raised only when an error occured while navigating,only HTTP status codes related to error can be accesed.Following are the list of HTTP Status codes that can be accessed.&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#000099;"&gt;HTTP_STATUS_BAD_GATEWAY (502)&lt;br /&gt;HTTP_STATUS_BAD_METHOD (405)&lt;br /&gt;HTTP_STATUS_BAD_REQUEST (400)&lt;br /&gt;HTTP_STATUS_CONFLICT (409)&lt;br /&gt;HTTP_STATUS_DENIED (401)&lt;br /&gt;HTTP_STATUS_FORBIDDEN (403)&lt;br /&gt;HTTP_STATUS_GATEWAY_TIMEOUT (504)&lt;br /&gt;HTTP_STATUS_GONE (410)&lt;br /&gt;HTTP_STATUS_LENGTH_REQUIRED (411)&lt;br /&gt;HTTP_STATUS_NONE_ACCEPTABLE (406)&lt;br /&gt;HTTP_STATUS_NOT_FOUND (404)&lt;br /&gt;HTTP_STATUS_NOT_SUPPORTED (501)&lt;br /&gt;HTTP_STATUS_PAYMENT_REQ (402)&lt;br /&gt;HTTP_STATUS_PRECOND_FAILED (412)&lt;br /&gt;HTTP_STATUS_PROXY_AUTH_REQ (407)&lt;br /&gt;HTTP_STATUS_REQUEST_TIMEOUT (408)&lt;br /&gt;HTTP_STATUS_REQUEST_TOO_LARGE (413)&lt;br /&gt;HTTP_STATUS_RETRY_WITH (449)&lt;br /&gt;HTTP_STATUS_SERVER_ERROR (500)&lt;br /&gt;HTTP_STATUS_SERVICE_UNAVAIL (503)&lt;br /&gt;HTTP_STATUS_UNSUPPORTED_MEDIA (415)&lt;br /&gt;HTTP_STATUS_URI_TOO_LONG (414)&lt;br /&gt;HTTP_STATUS_VERSION_NOT_SUP (505)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-8229162463307160163?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/8229162463307160163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=8229162463307160163' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/8229162463307160163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/8229162463307160163'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/07/capturing-http-status-codes-with.html' title='Capturing HTTP Status codes with &apos;WebBrowserControl&apos;'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-4450800793713836118</id><published>2008-07-28T05:22:00.000-07:00</published><updated>2008-07-28T05:37:10.273-07:00</updated><title type='text'>FAQS</title><content type='html'>This post is meant to give some information in question &amp;amp; answer pattern so that it'll be usefull for quick reference.I'l keep on adding stuff to these post when ever i found a deserving thing.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;1)Tips to Optimize performance of stored procedure.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;        A developer has wrriten a stored procedure.Its working fine, in the sense its giving the expected output for set of given input.But you've got a feedback that the performance is not good &amp;amp; you take neccesary action to improove the performance.In such a scenario following the below things may lead to better performance.&lt;br /&gt;&lt;br /&gt; a)Set 'SET NOCOUNT ON' before your stored procedure.This will stop sending number of rows affected as a result of this stored procedure.This can reduce network traffic.&lt;br /&gt;&lt;br /&gt;b)calling stored procedures using thier fully qualified names may increase performance.Using fully qualifies names increases the chances reusing  of stored procedure execution plans.&lt;br /&gt;&lt;br /&gt;c)use RETURN statement whereever possible.This stops sqlserver building resultset.&lt;br /&gt;&lt;br /&gt;e)dont use 'sp_' for stored procedures which are in databases other than in master database.If u hav a stored procedure with 'sp_' as a prefix , sql server will look in to the master database first &amp;amp; then looks for other database.&lt;br /&gt;&lt;br /&gt;f)If the StoredProcedure is very large ,then consider to split it to many sub storedprocedure's .the reason is when any structural changes occured  or bulk updates or inserts or deletes occured in table associated with stored procedure then stored procedure will recompile.If it is splitted in to many sub stored procedure's chances are more that few sub sp's will be recompiled.&lt;br /&gt;&lt;br /&gt;g)Try to avoid using temporary tables in sp.using of temp tables will reduces the chances of reusing the execution plan of stored procedure.&lt;br /&gt;&lt;br /&gt;h)try to avoid using DDL in stored procedure.using DDL in sp again redces the chance of reusing execution plan.&lt;br /&gt; &lt;br /&gt;           Checking for the above things helps in tracing where to refactor.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-4450800793713836118?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/4450800793713836118/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=4450800793713836118' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/4450800793713836118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/4450800793713836118'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/07/faqs.html' title='FAQS'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-6178742895161958169</id><published>2008-07-22T00:47:00.000-07:00</published><updated>2008-07-22T03:01:19.247-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='system restart with *msi installer package'/><title type='text'>How to promt for system restart after installing Windows Installer Package(*.msi) developed in Visual Studio</title><content type='html'>With Visual Studio one can develop variety of applications.After developing application the next step comes deploying application.For this Visual Studio supports project template called &lt;strong&gt;'Setup and Deployment Projects'&lt;/strong&gt;.With this project template one can develop setup.exe for any application developed using Visual Studio.But for some applications after deploying unless the system is restarted the application wont work as expected.The typical example for this kind of scenario is if application contains any registry additions.In such a cases its always recommended to prompt for system restart soon after completing installation.&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;This article describes how to achieve this.To do this one has to edit properties of &lt;strong&gt;*.msi&lt;/strong&gt; file.*.msi file is created in Debug or Release folder once your setup &amp;amp; deployment project in visual studio is bulit.&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;To edit properties of *.msi file one can do it in '&lt;strong&gt;Orca&lt;/strong&gt;' editor.&lt;/div&gt;&lt;div&gt;'&lt;strong&gt;Orca&lt;/strong&gt;' is a tool which can be used to edit properties of Windows Installer Packages(*.msi) .For more info on Orca visit &lt;a href="http://msdn.microsoft.com/en-us/library/aa370557.aspx"&gt;http://msdn.microsoft.com/en-us/library/aa370557.aspx&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;To downlaod Orca editor visit &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&amp;amp;displaylang=en&lt;/a&gt; &lt;/div&gt;&lt;br /&gt;&lt;div&gt;The next step is edit properties .open your *msi file in Orca editor with the help of '&lt;strong&gt;Open&lt;/strong&gt;' menu item in '&lt;strong&gt;File&lt;/strong&gt;' menu.Take a look at image below.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5225768899759604962" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_GAN78hPii8k/SIWpIIR0hOI/AAAAAAAAABM/c4FZlP1wm6k/s200/restart1.bmp" border="0" /&gt; After opening *.msi file in Orca editor you will find '&lt;strong&gt;Table&lt;/strong&gt;' pane on right side of the editor.Under '&lt;strong&gt;Table&lt;/strong&gt;' select '&lt;strong&gt;Property&lt;/strong&gt;' to select property table.This shows the list of properties &amp;amp; its values in right pane.Right click the 'Property' header &amp;amp; select &lt;strong&gt;'Add Row'&lt;/strong&gt; menu item.Then a pop up will be opened where name &amp;amp; value of property give.Give '&lt;strong&gt;REBOOT&lt;/strong&gt;' as name &amp;amp; '&lt;strong&gt;Force&lt;/strong&gt;' as value &amp;amp; save.Its done now.If you install that package(*.msi) then after completion of installing a automatic popup will appear prompting for system restart.Chekout image below.&lt;/p&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5225772918017487666" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_GAN78hPii8k/SIWsyBdJ8zI/AAAAAAAAABU/nqrwiFFl6C4/s320/restart.bmp" border="0" /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-6178742895161958169?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/6178742895161958169/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=6178742895161958169' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/6178742895161958169'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/6178742895161958169'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/07/how-to-promt-for-system-restart-after.html' title='How to promt for system restart after installing Windows Installer Package(*.msi) developed in Visual Studio'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_GAN78hPii8k/SIWpIIR0hOI/AAAAAAAAABM/c4FZlP1wm6k/s72-c/restart1.bmp' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-5236271318228467385</id><published>2008-07-12T03:53:00.000-07:00</published><updated>2008-07-12T04:43:23.449-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='HttpWebRequest Cookies Isssue'/><title type='text'>Cookie issue with 'HttpWebRequest' object</title><content type='html'>Recently i have a requirement to programatically  get the HTML mark up of a given url with C# coding.After a bit R&amp;amp;D work i found '&lt;span style="color: rgb(51, 102, 255);"&gt;HttpWebRequest&lt;/span&gt;' object in '&lt;span style="color: rgb(51, 102, 255);"&gt;System.Net&lt;/span&gt;' namespace  will server my purpose.Following lines of code can get the HTML mark up of a given URL.&lt;br /&gt;&lt;br /&gt;//code&lt;br /&gt;&lt;br /&gt;         &lt;span style="color: rgb(51, 102, 255);"&gt; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(&lt;span style="color: rgb(153, 0, 0);"&gt;"url"&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            HttpWebResponse res = (HttpWebResponse)req.GetResponse();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            Stream str = res.GetResponseStream();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            StreamReader streader = new StreamReader(str);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            string htmlContent = streader.ReadToEnd();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;in the above code '&lt;span style="color: rgb(51, 102, 255);"&gt;htmlContent&lt;/span&gt;' contains the HTML mark up of the &lt;span style="color: rgb(153, 0, 0);"&gt;'url'&lt;/span&gt; .Ideally this code should work for the all the urls.But there may be cases where the requested source is moved to some other web server &amp;amp; the request is redirected to new location by attaching some cookie to incoming request , in such a scenarios the above code wont work, it'l give excetion the reason is by default cookies are disable for 'HttpWebRequest'&lt;br /&gt;                       &lt;br /&gt;                                      The solution for this problem is to enable cookies for 'HttpWebRequest' object.This can be done with following piece of code.&lt;br /&gt;&lt;br /&gt;//code&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;req.CookieContainer = new CookieContainer();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note: setting of '&lt;span style="color: rgb(51, 51, 255);"&gt;CookieContainer&lt;/span&gt;' property of '&lt;span style="color: rgb(51, 51, 255);"&gt;HttpWebRequest&lt;/span&gt;' should be done before calling &lt;span style="color: rgb(51, 102, 255);"&gt;'GetResponse()'&lt;/span&gt; method.&lt;br /&gt;&lt;br /&gt;With this code cookies are enable for 'HttpWebRequest'.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-5236271318228467385?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/5236271318228467385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=5236271318228467385' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/5236271318228467385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/5236271318228467385'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/07/cookie-issue-with-httpwebrequest-object.html' title='Cookie issue with &apos;HttpWebRequest&apos; object'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1895044007297610042.post-8827714031445218478</id><published>2008-07-12T00:18:00.000-07:00</published><updated>2008-07-12T02:32:13.090-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='platform invoke'/><category scheme='http://www.blogger.com/atom/ns#' term='system menu'/><category scheme='http://www.blogger.com/atom/ns#' term='DllInport'/><title type='text'>Disable Close option on system menu for Windows Forms</title><content type='html'>This article decsribes about how to disable a close option of system menu  for a windows form with C#.This can be done by calling win API functions.&lt;br /&gt;&lt;br /&gt;    First let me explain what  '&lt;span style="font-weight: bold;"&gt;System menu&lt;/span&gt;' is ?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;System menu:&lt;/span&gt;&lt;br /&gt;-----------------&lt;br /&gt;In windows o/s for any opened window a button is added in the task bar.When clicked on the button the window will be opened if it is minimised and vice versa.When right clicked on task bar button a menu will be opened,technically this menu is know as '&lt;span style="font-weight: bold;"&gt;System menu&lt;/span&gt;',also called as &lt;span style="font-weight: bold;"&gt;Window menu&lt;/span&gt;'.This menu can also be accesed by by right clicking on title bar of the window &amp;amp; clicking on the icon on title bar of windThis consists menu options like '&lt;span style="font-weight: bold;"&gt;Close&lt;/span&gt;',&lt;span style="font-weight: bold;"&gt;'Minimise&lt;/span&gt;',&lt;span style="font-weight: bold;"&gt;'Maximise'&lt;/span&gt;,&lt;span style="font-weight: bold;"&gt;'Size'&lt;/span&gt;,&lt;span style="font-weight: bold;"&gt;'Move'&lt;/span&gt;,&lt;span style="font-weight: bold;"&gt;'Restore'&lt;/span&gt;.All these terms are self explanatory.Check out the image below.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_GAN78hPii8k/SHhhFwzpe3I/AAAAAAAAAA0/BdZP8nSMF_Y/s1600-h/system+menu.bmp"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_GAN78hPii8k/SHhhFwzpe3I/AAAAAAAAAA0/BdZP8nSMF_Y/s200/system+menu.bmp" alt="" id="BLOGGER_PHOTO_ID_5222030519564860274" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;          The present article explains about how disable any option in system menu.&lt;br /&gt;Win API provides set of methods to deal with menu &amp;amp; submenus.These methods can be used to modify the menu's.&lt;br /&gt;Following are the winAPI  functions needed for requirement&lt;br /&gt;1)&lt;span style="font-weight: bold;"&gt;GetSystemMenu&lt;/span&gt; ---- get access to system menu.&lt;br /&gt;2)&lt;span style="font-weight: bold;"&gt;EnableMenuItem&lt;/span&gt; --- modifies system menu.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;          To call this methods from C# code .Net framework provides a way called '&lt;span style="font-weight: bold;"&gt;Platform Invoke&lt;/span&gt;'.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;PlatformInvoke&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;                Platform Invoke concept allows to call methods from managed code which are in unmanaged DLL's. For more information on this ckeck out&lt;br /&gt;"http://msdn.microsoft.com/en-us/library/aa288468.aspx"&lt;br /&gt;&lt;br /&gt;                  To call a method in managed code first that method to be declered with &lt;span style="font-weight: bold;"&gt;[DLLImport]&lt;/span&gt;  attribure.This attribute should be  applied to methods which are declared  in managed code &amp;amp; actually implemented in unmanaged DLL.The code looks like this .&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;[DllImport("user32.dll")]&lt;/span&gt; &lt;span style="color: rgb(51, 102, 255);"&gt;private static extern IntPtr GetSystemMenu(IntPtr Hmenu, bool Brevert);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Parameters Info:&lt;br /&gt;---first parameter of above function is a handle to window.&lt;br /&gt;---Second parameter must be '&lt;span style="color: rgb(51, 102, 255);"&gt;false&lt;/span&gt;' so that the menu can be modified.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 102, 102);"&gt;Note:DllImport atribute takes Dll name as parameter.In our case its 'user32.dll'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(51, 102, 255);"&gt;[DllImport("user32.dll")]&lt;/span&gt; &lt;span style="color: rgb(51, 102, 255);"&gt; private static extern bool EnableMenuItem(IntPtr Hmenu, uint Uposition, uint UEnable);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Parameters Info:&lt;br /&gt;--Fisrt parameter is the  handle to system menu.Its return value of the method &lt;span style="color: rgb(51, 102, 255);"&gt;'GetSystemMenu'&lt;/span&gt;&lt;br /&gt;--Second parameter specifies the which menu item to be modified.Value of the parameter also depends upon the value of '&lt;span style="color: rgb(51, 102, 255);"&gt;UEnable&lt;/span&gt;' parameter.&lt;br /&gt;--third parameter is combination of values which indicates whether the menu item is enabled, disabled, or grayed.The combination of possible vales are MF_BYCOMMAND or MF_BYPOSITION and MF_ENABLED, MF_DISABLED, or MF_GRAYED.&lt;br /&gt;&lt;br /&gt;&lt;dl&gt;&lt;dt&gt;&lt;span class="clsLiteral"&gt;MF_BYCOMMAND&lt;/span&gt; &lt;/dt&gt;&lt;dd&gt;Indicates that &lt;i&gt;uIDEnableItem&lt;/i&gt; gives the identifier of the menu item.  If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified, the  MF_BYCOMMAND flag is the default flag. &lt;/dd&gt;&lt;dt&gt;&lt;span class="clsLiteral"&gt;MF_BYPOSITION&lt;/span&gt; &lt;/dt&gt;&lt;dd&gt;Indicates that &lt;i&gt;uIDEnableItem&lt;/i&gt; gives the zero-based relative position  of the menu item. &lt;/dd&gt;&lt;dt&gt;&lt;span class="clsLiteral"&gt;MF_DISABLED&lt;/span&gt; &lt;/dt&gt;&lt;dd&gt;Indicates that the menu item is disabled, but not grayed, so it cannot be  selected. &lt;/dd&gt;&lt;dt&gt;&lt;span class="clsLiteral"&gt;MF_ENABLED&lt;/span&gt; &lt;/dt&gt;&lt;dd&gt;Indicates that the menu item is enabled and restored from a grayed state so  that it can be selected. &lt;/dd&gt;&lt;dt&gt;&lt;span class="clsLiteral"&gt;MF_GRAYED&lt;/span&gt; &lt;/dt&gt;&lt;dd&gt;Indicates that the menu item is disabled and grayed so that it cannot be  selected.&lt;/dd&gt;&lt;/dl&gt;  values for the above constants can be found in winuser.h header file in windows platform SDK.&lt;br /&gt;&lt;br /&gt;These declarations to be made in global area of the code part of the form(like form.cs).&lt;br /&gt;After declaring the methods required the next step is to call that method in approptiate place.In this case form load event is appropriate place to call the methods.&lt;br /&gt;&lt;br /&gt;//Code in form load&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Values for the constants&lt;br /&gt;-------------------------&lt;br /&gt;      private const int MF_BYPOSITION = 0x00400;&lt;br /&gt;      private const int MF_GRAYED = 0x000001;&lt;br /&gt;      private const int MF_ENABLED = 0x000000;&lt;br /&gt;      private const int MF_BYCOMMAND = 0x00000;&lt;br /&gt;      private const int SC_CLOSE = 0xF060;&lt;br /&gt;      private const int SC_SIZE = 0xF000;&lt;br /&gt;      private const int SC_MOVE = 0xF010;&lt;br /&gt;      private const int SC_MAXIMIZE = 0xF030;&lt;br /&gt;&lt;br /&gt;After running the code system menu for the form  looks something like this.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_GAN78hPii8k/SHhtlo33RAI/AAAAAAAAAA8/4BzctanRP9g/s1600-h/system+menu1.bmp"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_GAN78hPii8k/SHhtlo33RAI/AAAAAAAAAA8/4BzctanRP9g/s200/system+menu1.bmp" alt="" id="BLOGGER_PHOTO_ID_5222044261330404354" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1895044007297610042-8827714031445218478?l=madhu-dotnetblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madhu-dotnetblog.blogspot.com/feeds/8827714031445218478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=1895044007297610042&amp;postID=8827714031445218478' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/8827714031445218478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1895044007297610042/posts/default/8827714031445218478'/><link rel='alternate' type='text/html' href='http://madhu-dotnetblog.blogspot.com/2008/07/disable-close-option-on-system-menu-for.html' title='Disable Close option on system menu for Windows Forms'/><author><name>Madhu</name><uri>http://www.blogger.com/profile/09578738599685666389</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05033304695083124855'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_GAN78hPii8k/SHhhFwzpe3I/AAAAAAAAAA0/BdZP8nSMF_Y/s72-c/system+menu.bmp' height='72' width='72'/><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>