<?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:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2288766597779679530</id><updated>2024-09-22T16:17:53.483-07:00</updated><category term="Encryption"/><category term="ASP.net"/><category term="Entity Framework"/><category term="Gridview"/><category term="Linq to Objects"/><category term="Reporting"/><category term="Windows Service"/><category term=".net"/><category term="C#"/><category term="CAS"/><category term="Decryptions"/><category term="File upload"/><category term="GetElementID"/><category term="Hashing"/><category term="Insertion"/><category term="Linq"/><category term="Report Viewer"/><category term="SOAP Header"/><category term="SQL"/><category term="String to Dataset"/><category term="Transaction"/><category term="WPF"/><category term="WebServices"/><category term="Webbrowser"/><category term="XLinq"/><category term="XML"/><category term="fileupload"/><category term="identity impersonation"/><category term="security"/><title type='text'>Advanced programming in C# and ASP.net</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>25</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-6905146285908060654</id><published>2014-03-30T01:05:00.001-07:00</published><updated>2014-03-30T02:40:40.219-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Encryption"/><category scheme="http://www.blogger.com/atom/ns#" term="fileupload"/><category scheme="http://www.blogger.com/atom/ns#" term="identity impersonation"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><title type='text'>Upload/Access a File to network folder in asp.net </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In my previous &lt;b&gt;&lt;a href=&quot;http://csharp-asp.blogspot.com/2014/03/working-with-fileupload-control-and-its.html&quot;&gt;POST&lt;/a&gt;&amp;nbsp;&lt;/b&gt;I had shown how to upload file in ASP.NET using the FileUpload control.&lt;br /&gt;
&lt;br /&gt;
There might me lot of cases where your web server might no hold the &#39;n&#39; number of files uploaded into the server. At this time your network guys may ask you to upload the file into a data server where you have lot of space. So, basically instead of storing it into the same server you will be forced to store it into a network folder.&lt;br /&gt;
&lt;br /&gt;
Storing into a network folder is not a big deal. But when you are in a domain and your company have lot of security policies, then you might get into troubles uploading the file into the network folder.&lt;br /&gt;
&lt;br /&gt;
First let me tell you how to show a network folder inside the FileUpload control.&lt;br /&gt;
Steps:-&lt;br /&gt;
1) Create a folder which is shared among Everyone to read/write let us say the path is&amp;nbsp;&lt;b&gt;\\smilu-pc\NetworkFolder\&lt;/b&gt;&lt;br /&gt;
2) Add the network path into the Fileupload&#39;s SaveAs method as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;protected void UploadFileButton_Click(object sender, EventArgs e)
{
  FileUploadDocuments.SaveAs(@&quot;\\smilu-pc\\NetworkFolder\\&quot; + FileUploadDocuments.FileName);
}
&lt;/pre&gt;
&lt;br /&gt;
If you have network access to this folder to write then you must be able to upload the files into it.&lt;br /&gt;
&lt;br /&gt;
Now, If you don&#39;t have network access to these folders once you publish the website, you might get errors and the file may not be uploaded into the folder.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above should not be the case always.&lt;br /&gt;
Your companies security policy will not allow you to share the folder for &quot;Everyone&quot; for writing/reading. So, It will be given to specific users. Here are some steps which will really help you to do these actions.&lt;br /&gt;
&lt;br /&gt;
The most common error which you will find is written below&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Exceptions:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;System.UnauthorizedAccessException: Access to the path &#39;&amp;nbsp;\\smilu-pc\NetworkFolder\filename.txt&#39; is denied&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
When you try to upload the file the above exceptions might appear to you. And you will be struggling giving permissions to folder. When you run locally this will work very smoothly. But when you run this from webserver it will always throw the above error.&lt;br /&gt;
&lt;br /&gt;
So, How can I solve this.&lt;br /&gt;
The best way to solve this is &lt;b&gt;Identity Impersonation.&lt;/b&gt;&amp;nbsp;You can look &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa292118(v=vs.71).aspx&quot;&gt;MSDN &lt;/a&gt;for its descriptions.&lt;br /&gt;
I&#39;ll give you a basic idea of it.&lt;br /&gt;
By default, Impersonation is disabled by asp.net and all the applications running in asp.net will not be having identity impersonation.&lt;br /&gt;
Identity Impersonation allows the Application to get authorized by a specific username and password when accessing the network folders or while doing some activities on the machines hence allowing it to work smoothly.&lt;br /&gt;
&lt;br /&gt;
How to enable Identity Impersonation?&lt;br /&gt;
&lt;br /&gt;
You can enable the Identity Impersonation in two ways.&lt;br /&gt;
1) Through web.config.&lt;br /&gt;
Adding the data into the Web.config is the best and the easiest way for working with Impersonation.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt; &amp;lt;identity impersonate=&quot;true&quot; userName=&quot;domain\smilu&quot; password=&quot;password&quot;/&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
Writing this code into your system.web section of your web.config file will allow you to safely work with your application now. The user SMILU must be having access to the folder to write/read whatever is needed. The same user should also be part of the webserver&#39;s too(This I&#39;m writing because I faced lot of issues when the user was not a part of my webserver)&lt;br /&gt;
&lt;br /&gt;
If all the things are taken care of, which I have written above, you can run your application and you can see the Files getting saved into the network folder safely.&lt;br /&gt;
&lt;br /&gt;
Hey see this, I can see your password now. Haha, now let me hack your machine.&lt;br /&gt;
Oops!! This is a major issue when you are working with Impersonation since the username and password is visible to others.&lt;br /&gt;
So, how can I solve this problem.&lt;br /&gt;
You can solve this in two ways&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Encrypting identity section in web.config&lt;/li&gt;
&lt;li&gt;Impersonation thorough code behind in asp.net&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
1) ENCRYPTING IDENTITY SECTION IN WEB.CONFIG&lt;/div&gt;
&lt;div&gt;
You are not joking right? Can we really encrypt the identity section in web.config??&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Yes, Its not only identity section you can encrypt any section you need like Connection strings, app settings, identity section using asp.net and the asp.net will decrypt it for you.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
How can you Encrypt a data in Web.config in asp.net?&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now, I will right the steps to encrypt the identity section in asp.net web.config file.&lt;/div&gt;
&lt;div&gt;
For this you must first open your command prompt and &amp;nbsp;navigate to your .net framework folder in your machine.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
eg: &lt;b&gt;C:\Windows\Microsoft.NET\Framework\v4.0.30319\&lt;/b&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
Now type the code below for encrypting the Identity section&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;aspnet_regiis -pef &quot;system.web/identity&quot; &quot;D:\Smilu\Testing\WebserviceCalls&quot;
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_O6Ye6hX4k3OO6GnCu4tkF3Nm5Lm_OksOKHjhdvOBPaQ4_5Hd4-xvMvhms0J-dgbtKEje9uzzsR0NwDtjmsAISbkhktwkvQbqqN30QxU-VzE76-xPbXgJfv7268sura2ORvzFn4rC05I/s1600/encryptidentity.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_O6Ye6hX4k3OO6GnCu4tkF3Nm5Lm_OksOKHjhdvOBPaQ4_5Hd4-xvMvhms0J-dgbtKEje9uzzsR0NwDtjmsAISbkhktwkvQbqqN30QxU-VzE76-xPbXgJfv7268sura2ORvzFn4rC05I/s1600/encryptidentity.PNG&quot; height=&quot;202&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
To know what is aspnet_regiis tool go to the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/k6h9cz8h(v=vs.80).aspx&quot;&gt;MSDN&lt;/a&gt; description of it.&lt;br /&gt;
&lt;br /&gt;
Just a go through the code above&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;-pef -&amp;nbsp;&lt;/b&gt;Will encrypt the section for you.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;-pdf &amp;nbsp;-&amp;nbsp;&lt;/b&gt;Will decrypt the section for you.&lt;/li&gt;
&lt;li&gt;&quot;&lt;b&gt;system.web/identity&lt;/b&gt;&quot; - The section which I need to encrypt&lt;/li&gt;
&lt;li&gt;&quot;&lt;b&gt;D:\Smilu\Testing\WebserviceCalls&lt;/b&gt;&quot; - The target web.config location in which i need to encrypt the data.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Let us see the web.config file before and after we run this command&lt;br /&gt;
&lt;br /&gt;
Before Encrypting identity section in web.config&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&amp;lt;identity impersonate=&quot;true&quot; userName=&quot;domain\smilu&quot; password=&quot;password&quot;/&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
Now after running the aspnet_regiis code on your command prompt&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;lt;identity configProtectionProvider=&quot;RsaProtectedConfigurationProvider&quot;&amp;gt;
 &amp;lt;EncryptedData Type=&quot;http://www.w3.org/2001/04/xmlenc#Element&quot;
xmlns=&quot;http://www.w3.org/2001/04/xmlenc#&quot;&amp;gt;
 &amp;lt;EncryptionMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#tripledes-cbc&quot; /&amp;gt;
 &amp;lt;KeyInfo xmlns=&quot;http://www.w3.org/2000/09/xmldsig#&quot;&amp;gt;
 &amp;lt;EncryptedKey xmlns=&quot;http://www.w3.org/2001/04/xmlenc#&quot;&amp;gt;
 &amp;lt;EncryptionMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#rsa-1_5&quot; /&amp;gt;
 &amp;lt;KeyInfo xmlns=&quot;http://www.w3.org/2000/09/xmldsig#&quot;&amp;gt;
  &amp;lt;KeyName&amp;gt;Rsa Key&amp;lt;/KeyName&amp;gt;
 &amp;lt;/KeyInfo&amp;gt;
 &amp;lt;CipherData&amp;gt;
  &amp;lt;CipherValue&amp;gt;uY1Wq5ZRRoWTuaR/4Xlst6/c1Rm9usaweg24XPd4OdMrJ4NDEkgM0vqECs4aCDy8F8JYX+lqzYRDHhj0V4QiHd16UPLqaGGfkPTm/3v6NRqM1Gv7r1fm2Rjagrc1V/zACL8OYHs/42VpDNpeyqDuf/70LLfTAaHjF9EX/tGJPBRRLqwfozHCv0Qjnm3i5Miuk0u19POzmX7+FZYQcnXNwN5EgvGeOKs+7FJNkidBHK1rVsdvjacpMSDICID2DQKlnuRPyXtjCJgqqFUawRolYEOuJGWgDZPAB/H0Ca/cRW3Dif3hCuD6qIc/LqqQo+xZOdXoJ/QPmO5oqURXge9SyQ==&amp;lt;/CipherValue&amp;gt;
 &amp;lt;/CipherData&amp;gt;
&amp;lt;/EncryptedKey&amp;gt;
&amp;lt;/KeyInfo&amp;gt;
&amp;lt;CipherData&amp;gt;
 &amp;lt;CipherValue&amp;gt;zqM9DF/qBA04DKIZ/LfcNLjw8RVh6B+yimvxMF3p+UVW6KTaQS/2t0TvwfbRC5QjFFDWCZkM/4EZmmOtXlY773S+7z8DS4wFeTdeOQN1zctCmxypE8eNPQ==&amp;lt;/CipherValue&amp;gt;
 &amp;lt;/CipherData&amp;gt;
&amp;lt;/EncryptedData&amp;gt;
&amp;lt;/identity&amp;gt;&lt;/span&gt;&lt;/pre&gt;
This is how it look when you encrypt the identity section. This section holds your username and password in an encrypted manner. If you can go through it you can find that here it has used&amp;nbsp;RsaProtectedConfigurationProvider for encryption&lt;br /&gt;
&lt;br /&gt;
So, This is how it is encrypted. Now, don&#39;t worry about how it works. Asp.net will decrypt it automatically when you are running the application.&lt;br /&gt;
&lt;br /&gt;
Now, you are safe with your username and password as no one can read this.&lt;br /&gt;
&lt;br /&gt;
Okay!! Now let me run the application.&lt;br /&gt;
&lt;br /&gt;
Ohh god! &amp;nbsp;I met up with an error HTTP 500.19.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;HTTP Error 500.19 - Configuration Section Encryption is Not Supported&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now, what you might be thinking? What is this guy talking about, He asked me to encrypt the section and now asp.net is saying encryption is not supported?&lt;br /&gt;
&lt;br /&gt;
Don&#39;t worry when you see this error. You have a very simple fix for this.&lt;br /&gt;
Add this line of code to your web.config section. This time its not in the system.web section instead you must write the code in system.webserver section&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&amp;lt;system.webServer&amp;gt;
   &amp;lt;validation validateIntegratedModeConfiguration=&quot;false&quot; /&amp;gt;
&amp;lt;/system.webServer&amp;gt;
&lt;/pre&gt;
Now, when you run the application it will run without that error.&lt;br /&gt;
&lt;br /&gt;
Here, I have gone though the steps and possible issues you will face when you are trying to upload a file into a network folder. Hope this will help you a lot in uploading the files using asp.net fileupload control&lt;br /&gt;
&lt;br /&gt;
In the next topic i will tell you how to programatically do impersonation.&lt;br /&gt;
&lt;br /&gt;
Happy programming!&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/6905146285908060654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/6905146285908060654' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6905146285908060654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6905146285908060654'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2014/03/uploadaccess-file-to-network-folder-in.html' title='Upload/Access a File to network folder in asp.net '/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_O6Ye6hX4k3OO6GnCu4tkF3Nm5Lm_OksOKHjhdvOBPaQ4_5Hd4-xvMvhms0J-dgbtKEje9uzzsR0NwDtjmsAISbkhktwkvQbqqN30QxU-VzE76-xPbXgJfv7268sura2ORvzFn4rC05I/s72-c/encryptidentity.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-4784156370666798030</id><published>2014-03-27T03:54:00.000-07:00</published><updated>2014-04-22T02:34:36.818-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.net"/><category scheme="http://www.blogger.com/atom/ns#" term="File upload"/><title type='text'>Working with FileUpload control and its errors in Asp.NET</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I&#39;m pretty sure you might be knowing how to work with the FileUpload control for uploading files.&lt;br /&gt;
I&#39;m talking about the normal classic FileUpload control which is available with Visual Studio.&lt;br /&gt;
&lt;br /&gt;
This is a tutorial in asp.net for working with FileUpload control.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;This blog post shows you about&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;How to upload a file using FileUpload control in asp.net&lt;/li&gt;
&lt;li&gt;Possible errors while uploading files into the &amp;nbsp;Webserver(IIS)&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
File upload controls can be used to upload any kind of file into a webserver or a desired location using ASP.NET&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This is pretty very easy one.&lt;/div&gt;
&lt;div&gt;
Let me make it simple for you.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
First, Create an ASP.NET application and keep a FileUpload control on it. let us say the name as FileUploadDocuments.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgujUdyKviEYdBaXeqDDT5phRCb5N6XSFSHr_GlhAz35bXQG5EcHfezID3dWYnDK5ZH15SjRlhBlkwd68LlHeQJgdUp69BfrE4fB0fD3RFIEtVww3RuvZtMVqVVwXCUvYMMEoQIZQSrXEQ/s1600/FileUploadControl.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgujUdyKviEYdBaXeqDDT5phRCb5N6XSFSHr_GlhAz35bXQG5EcHfezID3dWYnDK5ZH15SjRlhBlkwd68LlHeQJgdUp69BfrE4fB0fD3RFIEtVww3RuvZtMVqVVwXCUvYMMEoQIZQSrXEQ/s1600/FileUploadControl.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&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;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
----------------------&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
Now place a button let say UPLOAD FILE near the FileUpload control&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY5_EyoS7b4N7IZejMBJ5vGbi3IVJkL2X1ndKOA-r1RSBf-WsdUd9kKBZbwU9dTzxp4C5gu6_E40u2kvoR4-ZBStva6bwHxet1W8VmUQZCEbAnR1SFgrN7RSlsn_W7YQjnRlTnLmvEIJk/s1600/UploadFile.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto; text-align: left;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY5_EyoS7b4N7IZejMBJ5vGbi3IVJkL2X1ndKOA-r1RSBf-WsdUd9kKBZbwU9dTzxp4C5gu6_E40u2kvoR4-ZBStva6bwHxet1W8VmUQZCEbAnR1SFgrN7RSlsn_W7YQjnRlTnLmvEIJk/s1600/UploadFile.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now on the UploadFile_Click event write the code below&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;protected void UploadFileButton_Click(object sender, EventArgs e)
{
  FileUploadDocuments.SaveAs(@&quot;C:\smilu\&quot; + FileUploadDocuments.FileName);
}
&lt;/pre&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
Now, run your application. Select a file from your local machine. Click on the Upload button and that&#39;s it. Done!!&lt;br /&gt;
&lt;br /&gt;
Go to the physical location and you can find the Uploaded file there. &quot;C:\smilu\&quot;.&lt;br /&gt;
&lt;br /&gt;
How, simple is it right?&lt;br /&gt;
&lt;br /&gt;
Normally, I start like this. So, its easy for others to understand FileUploading. Now, you know which code actually uploads the file.&lt;br /&gt;
&lt;br /&gt;
Now, We need to know much more things about the control to exactly upload the file with no errors or saving it from uploading virus scripts or anything.&lt;br /&gt;
&lt;br /&gt;
So, what all things should be checked here. Let us say, I want my file size restricted to 10MB, only images, pdf, doc files should be uploaded, Whether the file is present in the physical location etc etc. So, how can I achieve this?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
1) I want to upload the Files into a folder inside my website&lt;/h3&gt;
&lt;br /&gt;
Its always better to upload files into the same website subfolders since all the files will be available for you. But, there are cases like if its a big application you cannot go with this approach since there might be too much files getting uploaded. So, you can use a network path or a physical path to an external HDD etc.&lt;br /&gt;
&lt;br /&gt;
Now, here we are talking about how to upload into a sub folder inside my website itself.&lt;br /&gt;
So, First create a folder inside your solution from Solution explorer.&lt;br /&gt;
steps:-&lt;br /&gt;
Right click on Solution-&amp;gt;Add-&amp;gt;NewFolder (in Visual Studio 2013)&lt;br /&gt;
Right Click on Solution-&amp;gt;NewFolder (in Visual Studio 2010)&lt;br /&gt;
Let us say the name given to that folder is &quot;UPLOADS&quot;&lt;br /&gt;
&lt;br /&gt;
Now I want to save the files into my uploads folder.&lt;br /&gt;
So, First i want to get the physical path of my Uploads folder. The physical path can be some thing like &quot;C:\inetpub\wwwroot\website\uploads\&quot;&lt;br /&gt;
But we don&#39;t know in the webserver where we are going to place the webiste. So, the location should be mapped dynamically into the website.&lt;br /&gt;
For getting the physical path of a website folder you can use the statement Server.MapPath.&lt;br /&gt;
So, change the fileUpload controls code to&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&amp;nbsp;FileUploadDocuments.SaveAs(Server.MapPath(&quot;~/Uploads/&quot;) + FileUploadDocuments.FileName);&lt;/pre&gt;
&lt;br /&gt;
Here Server.MapPath(&quot;~/Uploads/&quot;) will get the physical path of the upload folder and allows the file to be uploaded into that particular folder.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
2) Check whether the file is available in the physical location.&lt;/h3&gt;
&lt;br /&gt;
Why should we need this? I&#39;m selecting a file from physical location right?&lt;br /&gt;
Yes, You are selecting a file from Physical location. But what if after your selection the file got removed and then you tried to upload the file?&lt;br /&gt;
&lt;br /&gt;
So, we need to avoid this issue.&lt;br /&gt;
This can be cross checked by HasFile attribute of the FileUpload Control like&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;if (FileUploadDocuments.HasFile)
{
 FileUploadDocuments.SaveAs(@&quot;C:\smilu\&quot; + FileUploadDocuments.FileName);
}
else
{
 ErrorMessage.Text=&quot;The file does not exist in the physical path&quot;;

}
&lt;/pre&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This ensures the file you are about to upload is physically present in the drive.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
3) I want to restrict my file size to 10MB&lt;/h3&gt;
&lt;br /&gt;
Why should I check this?&lt;br /&gt;
If you doesn&#39;t check this your webserver or the location to which you are uploading will be soon filled with files. What if someone tries to upload files of 100MB each.&lt;br /&gt;
&lt;br /&gt;
So, We need to make use of all the available options given by FileUpload control in asp.net&lt;br /&gt;
How can we achieve this?&lt;br /&gt;
We can achieve this easily with the help of properly called&amp;nbsp;ContentLength. Content length will return the no of bytes of the file you are trying to upload. You can write the code like this.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;if (FileUploadDocuments.PostedFile.ContentLength &amp;lt; ((1024 * 10) * 1024))
{
FileUploadDocuments.SaveAs(@&quot;C:\smilu\&quot; + FileUploadDocuments.FileName);
}
else
{
ErrorMessage.Text=&quot;Your file is more than 10MB&quot;;
}
&lt;/pre&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
I have done the calculation like (1024 * 10) * 1024) because 10MB means the value will be&amp;nbsp;10485760 bytes. So, when you don&#39;t know exact value you think like this. 1MB=1024KB, 1KB=1024bytes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So above you restricted the user to upload files below 10 MB. So, when a user tries to upload a file above 10 MB you can show an error message&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
4) I want to upload only files with a specific type(PDF/JPG/DOCX)&lt;/h3&gt;
&lt;br /&gt;
Why you need this?&lt;br /&gt;
This is needed since your purpose will be a job application and no one should upload a Video as his CV. :-)&lt;br /&gt;
Definition is as simple as that.&lt;br /&gt;
&lt;br /&gt;
Now, how can you achieve this.&lt;br /&gt;
You can achieve this in many ways. My way of achieving is with the help of FileInfo class from System.IO and the ContentType property of the FileUpload control itself.&lt;br /&gt;
&lt;br /&gt;
The safest way is with the help of ContentType since no one can alter the file extension and upload a different file(Like an image with docx extension)&lt;br /&gt;
&lt;br /&gt;
You can write the code like below.&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;if (FileUploadDocuments.PostedFile.ContentType.ToUpper() == &quot;APPLICATION/PDF&quot; || FileUploadDocuments.PostedFile.ContentType.ToUpper() == &quot;IMAGE/JPG&quot; )
{
FileUploadDocuments.SaveAs(@&quot;C:\smilu\&quot; + FileUploadDocuments.FileName);
}
else
{
ErrorMessage.Text = &quot;Only PDF and JPG files are allowed&quot;;
}
&lt;/pre&gt;
&lt;br /&gt;
The above code will allow only PDF, and JPG files to be uploaded into the application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;TIP:&lt;/span&gt;&lt;/b&gt; Try printing FileUploadDocuments.PostedFile.ContentType when you upload different type of files and you will get all the desired content types.&lt;br /&gt;
&lt;br /&gt;
If you only want to check the extension of the file then go thorough this way&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;System.IO.FileInfo fi = new System.IO.FileInfo(FileUploadDocuments.FileName);
if (fi.Extension.ToUpper() == &quot;.DOCX&quot; || fi.Extension.ToUpper() == &quot;.DOC&quot;)
{
  FileUploadDocuments.SaveAs(@&quot;C:\smilu\&quot; + FileUploadDocuments.FileName);
}
else
{
  ErrorMessage.Text = &quot;Invalid document only DOC, DOCX files are allowed&quot;;
}&lt;/pre&gt;
&lt;br /&gt;
So, with the codes above you can upload a file in the safest way to your webserver.&lt;br /&gt;
&lt;br /&gt;
Now, let us see how the final code looks like with all these validations.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;protected void UploadFileButton_Click(object sender, EventArgs e)
 {
  System.IO.FileInfo fi = new System.IO.FileInfo(FileUploadDocuments.FileName);  
  if (FileUploadDocuments.HasFile)
  {
   if (FileUploadDocuments.PostedFile.ContentLength &amp;lt; ((1024 * 10) * 1024))
   {
    if (FileUploadDocuments.PostedFile.ContentType.ToUpper() == &quot;APPLICATION/PDF&quot; || FileUploadDocuments.PostedFile.ContentType.ToUpper() == &quot;IMAGE/JPG&quot; || fi.Extension.ToUpper() == &quot;.DOCX&quot; || fi.Extension.ToUpper() == &quot;.DOC&quot;)
    {
     FileUploadDocuments.SaveAs(Server.MapPath(&quot;~/Uploads/&quot;) + FileUploadDocuments.FileName);
    }
    else
    {
     ErrorMessage.Text = &quot;Only PDF/JPG/DOC/DOCX files are allowed&quot;;
    }
   }
   else
   {
    ErrorMessage.Text = &quot;Your file is more than 10MB&quot;;
   }
  }
  else
  {
   ErrorMessage.Text = &quot;The file does not exist in the physical path&quot;;
  }
}

&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
Now, when you run this it will work smoothly until you put this into a real Webserver.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;b&gt;Handling Errors&lt;/b&gt;&lt;/h3&gt;
&lt;br /&gt;
What&#39;s going to happen when you put this into a webserver. If you are beginner and you are working with the file upload control it can make you crazy with the errors appearing in the webservers.&lt;br /&gt;
First one will be exception due to the permission level of the folder&lt;br /&gt;
Always make sure you have set the write permission of the folder to IIS_IUSRS of the webserver machine.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVevlguw6ns2SsVSmx_eb2WCxcmX_OutI4NXtB-RMI32OyAu0f3rT9saJu3sMHOXhH0JUuBpYsB_zg_OMfkolluNAN_cHyVIvonxIlwnDzXFQbZpNHwgnUeb6i2d0P_MQVMSnSwiZ0Eq8/s1600/folderpermission.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVevlguw6ns2SsVSmx_eb2WCxcmX_OutI4NXtB-RMI32OyAu0f3rT9saJu3sMHOXhH0JUuBpYsB_zg_OMfkolluNAN_cHyVIvonxIlwnDzXFQbZpNHwgnUeb6i2d0P_MQVMSnSwiZ0Eq8/s1600/folderpermission.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will make sure that IIS users are allowed to write the files into the Uploads Folder. You just need to set the permission only for Uploads folder.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, Another error which you might have to face is the Max Request length reached error.&lt;br /&gt;
Whenever you try to upload a file above 4MB using FileUpload control into the Webserver, It will raise an error saying Max Request Length reached. This is because by default the max request length of our IIS setting is set to 4MB. when you get this error you must have to override the maxRequestLenth from web.config.&lt;br /&gt;
This can be done by adding a line of code in the web.config in the system.web section.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;lt;httpRuntime targetFramework=&quot;4.5.1&quot; maxRequestLength=&quot;1024000&quot; /&amp;gt;
&lt;/pre&gt;
In most cases the above code alone should handle the exception.&lt;br /&gt;
But in some cases even if you write the above code again you might get the same error. So, this time you will be worried thinking what happened. This is because in a minor case sometimes IIS will look into system.weberver section also.&lt;br /&gt;
So, you must override this in the system.webserver section too. If you don&#39;t have the system.webserver section you must add it into the web.config file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&amp;lt;system.webServer&amp;gt;    
    &amp;lt;security&amp;gt;
      &amp;lt;requestFiltering&amp;gt;
        &amp;lt;requestLimits maxAllowedContentLength=&quot;524288000&quot;/&amp;gt;
      &amp;lt;/requestFiltering&amp;gt;
    &amp;lt;/security&amp;gt;
  &amp;lt;/system.webServer&amp;gt;&lt;/pre&gt;
Now, this must allow you to upload files upto 500MB of size.&lt;br /&gt;
&lt;br /&gt;
So, have a great day. My next blog will be containing how to upload file into a network folder and what all thre problems that you will face in that. How to store files into a network folder with the help of Identity Impersonation, dynamic impersonation, Identity impersonation encryption etc.&lt;br /&gt;
&lt;br /&gt;
If you are working with .NET Framework 4.0 sometimes even with all the above codes you might get an error &quot;Page cannot be displayed&quot;.&lt;br /&gt;
So, if you face this error write the below code after the security section in System.webserver&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid rgb(219, 219, 219); margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&amp;lt;modules runAllManagedModulesForAllRequests=&quot;true&quot;/&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
Now, the website should work perfectly&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/4784156370666798030/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/4784156370666798030' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4784156370666798030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4784156370666798030'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2014/03/working-with-fileupload-control-and-its.html' title='Working with FileUpload control and its errors in Asp.NET'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgujUdyKviEYdBaXeqDDT5phRCb5N6XSFSHr_GlhAz35bXQG5EcHfezID3dWYnDK5ZH15SjRlhBlkwd68LlHeQJgdUp69BfrE4fB0fD3RFIEtVww3RuvZtMVqVVwXCUvYMMEoQIZQSrXEQ/s72-c/FileUploadControl.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-794687141292126324</id><published>2012-03-27T00:26:00.000-07:00</published><updated>2012-03-27T00:26:41.625-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SOAP Header"/><category scheme="http://www.blogger.com/atom/ns#" term="WebServices"/><title type='text'>Add SOAP Header to your XML WebService</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;This will show how to add a SOAP Header to a WebService.&lt;br /&gt;
//namespace&lt;br /&gt;
using System.Web.Services.Protocols;&lt;br /&gt;
&lt;br /&gt;
Creating the Header.&lt;br /&gt;
Create a Class which is Inherited from SoapHeader Class.&lt;br /&gt;
&lt;block&gt;&lt;br /&gt;
&lt;br /&gt;
public class UserAuthHeader : SoapHeader&lt;br /&gt;
{&lt;br /&gt;
public string UserName;&lt;br /&gt;
public string Password;&lt;br /&gt;
}&lt;br /&gt;
&lt;/block&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;block&gt;&lt;br /&gt;
[WebService(Namespace = &quot;http://www.smilu.net/&quot;)]&lt;br /&gt;
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]&lt;br /&gt;
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. &lt;br /&gt;
// [System.Web.Script.Services.ScriptService]&lt;br /&gt;
public class Service : System.Web.Services.WebService&lt;br /&gt;
{&lt;br /&gt;
public UserAuthHeader userauthentication;&lt;br /&gt;
public Service () {&lt;br /&gt;
&lt;br /&gt;
//Uncomment the following line if using designed components &lt;br /&gt;
//InitializeComponent(); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[WebMethod,SoapHeader(&quot;userauthentication&quot;)]&lt;br /&gt;
public string HelloWorld() {&lt;br /&gt;
if (userauthentication.UserName == &quot;smilu&quot; &amp;amp;&amp;amp; userauthentication.Password == &quot;pass&quot;)&lt;br /&gt;
{&lt;br /&gt;
return &quot;Hello World&quot;;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
return &quot;access denied&quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;/block&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
For calling the same inside a Website check the code below&lt;br /&gt;
&lt;block&gt;&lt;br /&gt;
protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
WithHeader.Service sc = new WithHeader.Service();&lt;br /&gt;
WithHeader.UserAuthHeader uh = new WithHeader.UserAuthHeader();&lt;br /&gt;
uh.UserName = &quot;smilu&quot;;&lt;br /&gt;
uh.Password = &quot;pass&quot;;&lt;br /&gt;
sc.UserAuthHeaderValue = uh;&lt;br /&gt;
Response.Write(sc.HelloWorld());&lt;br /&gt;
}&lt;br /&gt;
&lt;/block&gt;&lt;br /&gt;
Here UserAuthHeader is the Class name of the Header which we created.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/794687141292126324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/794687141292126324' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/794687141292126324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/794687141292126324'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2012/03/add-soap-header-to-your-xml-webservice.html' title='Add SOAP Header to your XML WebService'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-8511761166520439777</id><published>2011-11-23T01:20:00.000-08:00</published><updated>2014-04-01T23:22:07.024-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Report Viewer"/><category scheme="http://www.blogger.com/atom/ns#" term="Reporting"/><title type='text'>Dynamically create a Report in ReportViewer</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here im going to tell you about how to create a report using a report viewer by coding.&lt;br /&gt;
&lt;br /&gt;
First you should create a typed DataSet with the structure of your Table(or how you need the table to be).&lt;br /&gt;
Now the next step is to create a report&lt;br /&gt;
&lt;br /&gt;
Website/Project -&amp;gt; Add New Item -&amp;gt; Report&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6CXPFLfuTiiVKkKKRtHeN2zgwHgzPEx0YDFrUmeQCX3wHo-k58wbVxUEHCEAd2AWwy3t8RkYqhOt5lypDTySyNN-E2nr3YRHOA4c7Xld0m9RXVDqjHjBKSqXA-liLD4DQM50IREavzMk/s1600/createreport.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6CXPFLfuTiiVKkKKRtHeN2zgwHgzPEx0YDFrUmeQCX3wHo-k58wbVxUEHCEAd2AWwy3t8RkYqhOt5lypDTySyNN-E2nr3YRHOA4c7Xld0m9RXVDqjHjBKSqXA-liLD4DQM50IREavzMk/s320/createreport.png&quot; height=&quot;205&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Give a name for it.&lt;br /&gt;
After this Select the Dataset from the New menu displayed in the rdlc file&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvVLoDwMtsR0v0f2ax_bYdldeV1IK4rw8eA5nZemZqSc8G70vcHYRlGJFxb03Ep1IP6DG3YalrKyovqYH73FXC5kiLV4PkVbiuJTOOQpYUVNe1Mbe_HoEwUvatNhb6PmKtDNCEjSViTdA/s1600/selectDataSource.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvVLoDwMtsR0v0f2ax_bYdldeV1IK4rw8eA5nZemZqSc8G70vcHYRlGJFxb03Ep1IP6DG3YalrKyovqYH73FXC5kiLV4PkVbiuJTOOQpYUVNe1Mbe_HoEwUvatNhb6PmKtDNCEjSViTdA/s320/selectDataSource.png&quot; height=&quot;249&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
The dataset will be diplayed in the report data window.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrKnugrtKRYld7VKuqINHAqQF8qlfMyirKf2MM8qn9_f4yj11CAoTQpGrLruYUYPvOSOWrrehgDOne8ch8h75U652wLsOO_Yu_oPGZMaMZZUkqAV8I4NCSX853NHnXJOrxOV8B81texyk/s1600/SelectDataset.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrKnugrtKRYld7VKuqINHAqQF8qlfMyirKf2MM8qn9_f4yj11CAoTQpGrLruYUYPvOSOWrrehgDOne8ch8h75U652wLsOO_Yu_oPGZMaMZZUkqAV8I4NCSX853NHnXJOrxOV8B81texyk/s640/SelectDataset.png&quot; height=&quot;417&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
You must have to provide a Name for the dataset. In DataSource you will get the Typed DataSet you created.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Select the DataTable you created in the Dataset in the AvailableDatasets section and click OK.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now, You will get the information in the left pane window.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_f2uPbugnXUfUYUDDjKHYRvtnQ3RzeCxl17Gah0EdDsa_LAMiZUWbw4esbwYKc3QwQ7tw2xPyKguzyk1V84Xq5GgyCLb6VJceRoLcRHuDF12kvGH9ZMcjE9-eSQCrXMYE_Z450CQQ5Xw/s1600/datasetCreated.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_f2uPbugnXUfUYUDDjKHYRvtnQ3RzeCxl17Gah0EdDsa_LAMiZUWbw4esbwYKc3QwQ7tw2xPyKguzyk1V84Xq5GgyCLb6VJceRoLcRHuDF12kvGH9ZMcjE9-eSQCrXMYE_Z450CQQ5Xw/s400/datasetCreated.png&quot; height=&quot;400&quot; width=&quot;257&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Above you can see the Dataset added to the Table. Here the DataSet name given by me is DataSetSmilu. You should remember this name when we Bind the data from the program....&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now you can right click on the report create a table in the Report page and add the Fileds shown above like this.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT_XBmxt2XElHsNquDxKsFZOBI-QYoIYZu9mL9YaSG1YRBcbR9DVuCWxnkMpjC1YaFjETAyf9c_Dj5bdofh37hqpcfmSIhkm5w8efy7i3PMcpyZ3BAy6i0q-Z6ZWhvQW4C4EBt1foBcNQ/s1600/table.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT_XBmxt2XElHsNquDxKsFZOBI-QYoIYZu9mL9YaSG1YRBcbR9DVuCWxnkMpjC1YaFjETAyf9c_Dj5bdofh37hqpcfmSIhkm5w8efy7i3PMcpyZ3BAy6i0q-Z6ZWhvQW4C4EBt1foBcNQ/s400/table.png&quot; height=&quot;348&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXcFBKZOTwfoNGMcWNjx9BEyLJeC-44lenQzLUjchj7yts0iC-b5-JLgV4hrUbsF4-y2C8JY3ZXcGohifA-k0L6d18lP-NUNVMEPMZ16EOkbjA42-qjyBlR7OwMsT_tK9orjonnb2E1c0/s1600/bindtoTable.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXcFBKZOTwfoNGMcWNjx9BEyLJeC-44lenQzLUjchj7yts0iC-b5-JLgV4hrUbsF4-y2C8JY3ZXcGohifA-k0L6d18lP-NUNVMEPMZ16EOkbjA42-qjyBlR7OwMsT_tK9orjonnb2E1c0/s400/bindtoTable.png&quot; height=&quot;147&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Now you have the report file to be attached with the Report Viewer. You can add images, header etc to this page...&lt;br /&gt;
&lt;br /&gt;
Now create a new WebForm.&lt;br /&gt;
From the ToolBox add a Ajax ScriptManager into the page&lt;br /&gt;
Now from the Reports Section add a Report Viewer into the page.&lt;br /&gt;
Select the ToolTip of the ReportViewer and Select the .rdlc file that you have created.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp-yjnAQgvXlRnNjOJUv-sds-JJVu6qlNs9bPgWBLiNvYpZY3OcdilybwtsZaqRvPGhl0-jJIS7vCJJNmFbKCe6Yos8wIO1kk-YkIHQgWZWbwDzLBmgHm5urzAv0ABkfEubDOUK5f9TDE/s1600/selectRDLF.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp-yjnAQgvXlRnNjOJUv-sds-JJVu6qlNs9bPgWBLiNvYpZY3OcdilybwtsZaqRvPGhl0-jJIS7vCJJNmFbKCe6Yos8wIO1kk-YkIHQgWZWbwDzLBmgHm5urzAv0ABkfEubDOUK5f9TDE/s1600/selectRDLF.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now whenever you add a Report.rdlc file an ObjectDataSource will be added to the page. We dont need that objectdatasource for the working here...&lt;br /&gt;
So You can delete the ObjectDataSource.&lt;br /&gt;
Now you should go to Source of the Page and remove the ObjectDataSource Link on the LocalReport section of Reportviewer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;rsweb:ReportViewer ID=&quot;ReportViewer1&quot; runat=&quot;server&quot; Font-Names=&quot;Verdana&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Font-Size=&quot;8pt&quot; InteractiveDeviceInfos=&quot;(Collection)&quot;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WaitMessageFont-Names=&quot;Verdana&quot; WaitMessageFont-Size=&quot;14pt&quot; Width=&quot;651px&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;LocalReport ReportPath=&quot;rerportsmilu.rdlc&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;DataSources&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;rsweb:ReportDataSource /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/DataSources&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/LocalReport&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/rsweb:ReportViewer&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After editing the form should look like this.&lt;br /&gt;
&lt;br /&gt;
Now to our coding part.&lt;br /&gt;
Goto your codebehind file. ie the .cs file of the page and bind the data to the dataset.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;using &lt;/span&gt;System.Data.SqlClient;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;using &lt;/span&gt;Microsoft.Reporting.WebForms;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;using &lt;/span&gt;System.Web.Configuration;&lt;br /&gt;
&lt;br /&gt;
//code in page load or some methods..&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;smiluDS &lt;/span&gt;tDs = new &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;smiluDS&lt;/span&gt;();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6fa8dc;&quot;&gt;SqlConnection &lt;/span&gt;con = &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;new &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; color: #3d85c6;&quot;&gt;SqlConnection&lt;/span&gt;(WebConfigurationManager.ConnectionStrings[&quot;NationalBankConnectionString&quot;].ConnectionString);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6fa8dc;&quot;&gt;SqlDataAdapter &lt;/span&gt;&lt;/span&gt;da = new &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6fa8dc;&quot;&gt;SqlDataAdapter&lt;/span&gt;(&quot;Select * from Employee&quot;, con);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; da.Fill(tDs, tDs.Tables[0].TableName);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;ReportDataSource &lt;/span&gt;&lt;/span&gt;rDs = new &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;ReportDataSource&lt;/span&gt;(&quot;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;DataSetSmilu&lt;/span&gt;&quot;, tDs.Tables[0]);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ReportViewer1.LocalReport.DataSources.Clear();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ReportViewer1.LocalReport.DataSources.Add(rDs);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ReportViewer1.LocalReport.Refresh();&lt;br /&gt;
//code complete&lt;br /&gt;
&lt;br /&gt;
In the above code the We are using a SqlDataAdapter to get the data.&lt;br /&gt;
Now since we are using a TypedDataSet you should create an instance of the TypedDataSet itself.. Here it is &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3d85c6;&quot;&gt;smiluDS. &lt;/span&gt;Now &amp;nbsp;a ReportDataSource should be created for the reportviewer. In the report viewer we should specify the DataSet which we have created in the RDLC file and data to be Binded into it..&lt;br /&gt;
&lt;br /&gt;
Try to run it.. you will get the d&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/8511761166520439777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/8511761166520439777' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/8511761166520439777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/8511761166520439777'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2011/11/dynamically-create-report-in.html' title='Dynamically create a Report in ReportViewer'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6CXPFLfuTiiVKkKKRtHeN2zgwHgzPEx0YDFrUmeQCX3wHo-k58wbVxUEHCEAd2AWwy3t8RkYqhOt5lypDTySyNN-E2nr3YRHOA4c7Xld0m9RXVDqjHjBKSqXA-liLD4DQM50IREavzMk/s72-c/createreport.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-5447325971282310958</id><published>2011-11-21T04:44:00.001-08:00</published><updated>2011-11-21T04:44:31.321-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Windows Service"/><title type='text'>VB to C# Application Path in WindowsService</title><content type='html'>This method in VB.NET can be written like the below reflection method. The below method gets you the location of your application&lt;br /&gt;
My.Application.Info.DirectoryPath&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
System.Reflection.Assembly.GetExecutingAssembly().Location;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/5447325971282310958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/5447325971282310958' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/5447325971282310958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/5447325971282310958'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2011/11/vb-to-c-application-path-in.html' title='VB to C# Application Path in WindowsService'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-9073944652966954294</id><published>2010-08-31T00:12:00.000-07:00</published><updated>2010-08-31T00:28:48.541-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Entity Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="Insertion"/><title type='text'>Insertion Using Entity Model</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEoObkH_5GnPx7i5Q4bZmFgr2ODXMFNB0ZOiMskYjIb7vw8-om7ATL0rZwVQ4xZBf2IOOUweAhJ-SIDBev23uL0eh4nCjEx7B1PMb6Qp-tMpuVR0BX_5dclpoD8F1l-VqgB9KhhWQj4ws/s1600/Nation.JPG&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 230px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEoObkH_5GnPx7i5Q4bZmFgr2ODXMFNB0ZOiMskYjIb7vw8-om7ATL0rZwVQ4xZBf2IOOUweAhJ-SIDBev23uL0eh4nCjEx7B1PMb6Qp-tMpuVR0BX_5dclpoD8F1l-VqgB9KhhWQj4ws/s320/Nation.JPG&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5511468709078756610&quot; /&gt;&lt;/a&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#0000EE;&quot;&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEoObkH_5GnPx7i5Q4bZmFgr2ODXMFNB0ZOiMskYjIb7vw8-om7ATL0rZwVQ4xZBf2IOOUweAhJ-SIDBev23uL0eh4nCjEx7B1PMb6Qp-tMpuVR0BX_5dclpoD8F1l-VqgB9KhhWQj4ws/s1600/Nation.JPG&quot;&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;color:#0000EE;&quot;&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/span&gt;This is the Entity data Model NationalBankEntities3 in the program.&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;We are going to  add Items into the table EmployeeDetail&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Now we must write the code like below&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;NationalBankModel3.NationalBankEntities3 m = new NationalBankModel3.NationalBankEntities3();&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;        NationalBankModel3.EmployeeDetail Emp = new NationalBankModel3.EmployeeDetail() { EmpName = &quot;Smilu&quot;, EmpAddress = &quot;EKM&quot;, EmpPhNo = &quot;987654&quot;, EmpDob =Convert.ToDateTime(&quot;01/01/01&quot;) };&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;        m.AddToEmployeeDetails(Emp);&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;        m.SaveChanges();&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Here AddToEmployeeDetails will be the method which will insert the data of the Entity we send.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;SaveChages() will store the data into the table&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/9073944652966954294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/9073944652966954294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/9073944652966954294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/9073944652966954294'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/08/insertion-using-entity-model.html' title='Insertion Using Entity Model'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEoObkH_5GnPx7i5Q4bZmFgr2ODXMFNB0ZOiMskYjIb7vw8-om7ATL0rZwVQ4xZBf2IOOUweAhJ-SIDBev23uL0eh4nCjEx7B1PMb6Qp-tMpuVR0BX_5dclpoD8F1l-VqgB9KhhWQj4ws/s72-c/Nation.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-4846680276707400981</id><published>2010-08-10T00:25:00.000-07:00</published><updated>2010-08-10T00:33:28.829-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linq"/><category scheme="http://www.blogger.com/atom/ns#" term="XLinq"/><title type='text'>Linq to XML</title><content type='html'>Here we are just going to see how we can associate XML with LinQ.&lt;br /&gt;&lt;br /&gt;First create an XML file with the structure like this &lt;a href=&quot;http://csharp-asp.blogspot.com/2010/08/studentsxml-file.html&quot;&gt;CLICK HERE&lt;/a&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now add a GridView to your design.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We need &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;System.Xml.Linq; &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;namespace for working of XLINQ&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now in the page load event add the code like this..&lt;/div&gt;&lt;div&gt;------------------------------------------------------&lt;/div&gt;&lt;div&gt;&lt;div&gt;var query = from s in XElement.Load(MapPath(&quot;Students.xml&quot;)).Elements(&quot;Student1&quot;)&lt;/div&gt;&lt;div&gt;                    select new&lt;/div&gt;&lt;div&gt;                    {&lt;/div&gt;&lt;div&gt;                        Name = (string)s.Element(&quot;StName&quot;),&lt;/div&gt;&lt;div&gt;                        Address = (string)s.Element(&quot;StAddress&quot;),&lt;/div&gt;&lt;div&gt;                        PhNo = (string)s.Element(&quot;StPHNO&quot;),&lt;/div&gt;&lt;div&gt;                        flag = (int)s.Element(&quot;Flag&quot;)&lt;/div&gt;&lt;div&gt;                    };&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;GridView1.DataSource=query;&lt;/div&gt;&lt;div&gt;GridView1.DataBind();&lt;/div&gt;&lt;div&gt;------------------------------------------------------&lt;/div&gt;&lt;div&gt;In the above code we are using XElement.Load method to Load the Students.xml file and we must mention the Node inside which we have put the informations.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(string)s.Element(&quot;StName&quot;)&lt;/div&gt;&lt;div&gt;The above method converts the data inside the Node to the type we have specified and stores into it....&lt;/div&gt;&lt;div&gt;When we execute it we will get a GridView which contains columns Name, Address, PhNo, and Flag..&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/4846680276707400981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/4846680276707400981' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4846680276707400981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4846680276707400981'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/08/linq-to-xml.html' title='Linq to XML'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-6360003109798558386</id><published>2010-08-10T00:21:00.000-07:00</published><updated>2010-08-10T00:25:34.666-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><title type='text'>Students.XML File</title><content type='html'>&amp;lt;Students&amp;gt;&lt;br /&gt;  &amp;lt;Student&amp;gt;&lt;br /&gt;  &amp;lt;StID&amp;gt;S001&amp;lt;/StID&amp;gt;&lt;br /&gt;  &amp;lt;StName&amp;gt;Simi&amp;lt;/StName&amp;gt;&lt;br /&gt;  &amp;lt;StAddress&amp;gt;EKM&amp;lt;/StAddress&amp;gt;&lt;br /&gt;  &amp;lt;StPHNO&amp;gt;987654123&amp;lt;/StPHNO&amp;gt;&lt;br /&gt;  &amp;lt;Flag&amp;gt;1&amp;lt;/Flag&amp;gt;&lt;br /&gt;  &amp;lt;/Student&amp;gt;&lt;br /&gt;  &amp;lt;Student&amp;gt;&lt;br /&gt;    &amp;lt;StID&amp;gt;S002&amp;lt;/StID&amp;gt;&lt;br /&gt;    &amp;lt;StName&amp;gt;Ravi&amp;lt;/StName&amp;gt;&lt;br /&gt;    &amp;lt;StAddress&amp;gt;EKM&amp;lt;/StAddress&amp;gt;&lt;br /&gt;    &amp;lt;StPHNO&amp;gt;654987&amp;lt;/StPHNO&amp;gt;&lt;br /&gt;    &amp;lt;Flag&amp;gt;0&amp;lt;/Flag&amp;gt;&lt;br /&gt;  &amp;lt;/Student&amp;gt;&lt;br /&gt;  &amp;lt;Student&amp;gt;&lt;br /&gt;    &amp;lt;StID&amp;gt;S003&amp;lt;/StID&amp;gt;&lt;br /&gt;    &amp;lt;StName&amp;gt;Manu&amp;lt;/StName&amp;gt;&lt;br /&gt;    &amp;lt;StAddress&amp;gt;TVM&amp;lt;/StAddress&amp;gt;&lt;br /&gt;    &amp;lt;StPHNO&amp;gt;987654123&amp;lt;/StPHNO&amp;gt;&lt;br /&gt;    &amp;lt;Flag&amp;gt;1&amp;lt;/Flag&amp;gt;&lt;br /&gt;  &amp;lt;/Student&amp;gt;&lt;br /&gt;  &amp;lt;Student&amp;gt;&lt;br /&gt;    &amp;lt;StID&amp;gt;S004&amp;lt;/StID&amp;gt;&lt;br /&gt;    &amp;lt;StName&amp;gt;Sooraj&amp;lt;/StName&amp;gt;&lt;br /&gt;    &amp;lt;StAddress&amp;gt;EKM&amp;lt;/StAddress&amp;gt;&lt;br /&gt;    &amp;lt;StPHNO&amp;gt;64568&amp;lt;/StPHNO&amp;gt;&lt;br /&gt;    &amp;lt;Flag&amp;gt;0&amp;lt;/Flag&amp;gt;&lt;br /&gt;  &amp;lt;/Student&amp;gt;&lt;br /&gt;  &amp;lt;Student&amp;gt;&lt;br /&gt;    &amp;lt;StID&amp;gt;S005&amp;lt;/StID&amp;gt;&lt;br /&gt;    &amp;lt;StName&amp;gt;Remya&amp;lt;/StName&amp;gt;&lt;br /&gt;    &amp;lt;StAddress&amp;gt;EKM&amp;lt;/StAddress&amp;gt;&lt;br /&gt;    &amp;lt;StPHNO&amp;gt;987654123&amp;lt;/StPHNO&amp;gt;&lt;br /&gt;    &amp;lt;Flag&amp;gt;1&amp;lt;/Flag&amp;gt;&lt;br /&gt;  &amp;lt;/Student&amp;gt;  &lt;br /&gt;&amp;lt;/Students&amp;gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/6360003109798558386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/6360003109798558386' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6360003109798558386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6360003109798558386'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/08/studentsxml-file.html' title='Students.XML File'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-6409076916782413304</id><published>2010-08-09T01:04:00.000-07:00</published><updated>2010-08-09T01:15:19.066-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linq to Objects"/><title type='text'>JOIN - Linq to Objects</title><content type='html'>&lt;div&gt;We have two List&lt;&gt; methods namely GetStudents() which get us the information about the Students and GetFlagNames() which give us information about Flag.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public List&lt;student&gt; GetStudents()&lt;/div&gt;&lt;div&gt;&lt;div&gt;    {&lt;/div&gt;&lt;div&gt;        return new List&lt;student&gt;&lt;/div&gt;&lt;div&gt;        {&lt;/div&gt;&lt;div&gt;            new Student{Name=&quot;Smilu&quot;,Address=&quot;EKM&quot;,PhNo=&quot;987654&quot;,flag=1},&lt;/div&gt;&lt;div&gt;            new Student{Name=&quot;JK&quot;, Address=&quot;Parur&quot;,PhNo=&quot;897643&quot;,flag=0},&lt;/div&gt;&lt;div&gt;            new Student{Name=&quot;Kiran&quot;, Address=&quot;EKM&quot;,PhNo=&quot;798654&quot;,flag=1}&lt;/div&gt;&lt;div&gt;        };&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;    public List&lt;flagname&gt; GetFlagNames()&lt;/div&gt;&lt;div&gt;    {&lt;/div&gt;&lt;div&gt;        return new List&lt;flagname&gt;&lt;/div&gt;&lt;div&gt;        {&lt;/div&gt;&lt;div&gt;            new FlagName{flagID=0,flagName=&quot;CS&quot;},&lt;/div&gt;&lt;div&gt;            new FlagName{flagID=1,flagName=&quot;Network&quot;}&lt;/div&gt;&lt;div&gt;        };&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;/div&gt;&lt;div&gt;---------------------------------------------------&lt;/div&gt;&lt;div&gt;We store the list object into a variable called &quot;mystudents&quot; and &quot;flags&quot; respectively...&lt;/div&gt;&lt;div&gt;&lt;div&gt;        var mystudents = GetStudents();&lt;/div&gt;&lt;div&gt;        var flags = GetFlagNames();&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This  query represents the Joining using LinQ&lt;/div&gt;&lt;div&gt;        var query = from s in mystudents&lt;/div&gt;&lt;div&gt;                    join f in flags on s.flag equals f.flagID&lt;/div&gt;&lt;div&gt;                    select new { s.Name, s.PhNo, f.flagName };&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/6409076916782413304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/6409076916782413304' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6409076916782413304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6409076916782413304'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/08/join-linq-to-objects.html' title='JOIN - Linq to Objects'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-4852352982094431920</id><published>2010-08-08T21:24:00.000-07:00</published><updated>2010-08-08T21:38:22.060-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linq to Objects"/><title type='text'>Linq to Objects - Arithmetic Operations</title><content type='html'>Linq to objects can have arithmetic operations like &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Min&lt;/li&gt;&lt;li&gt;Max&lt;/li&gt;&lt;li&gt;Average&lt;/li&gt;&lt;li&gt;Sum&lt;/li&gt;&lt;li&gt;Count etc....&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;This is the List collection we are going to use....&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;public List&lt;student&gt; GetStudents()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;    {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        return new List&lt;student&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            new Student{Name=&quot;Smilu&quot;,Address=&quot;EKM&quot;,PhNo=&quot;987654&quot;,flag=1},&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            new Student{Name=&quot;JK&quot;, Address=&quot;Parur&quot;,PhNo=&quot;897643&quot;,flag=0},&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            new Student{Name=&quot;Binu&quot;, Address=&quot;EKM&quot;,PhNo=&quot;798654&quot;,flag=1}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        };&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;    }&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;--------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;For using this we need to first create a var variable and assign the list into it...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;var StudentInfo=GetStudents();&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt; LabelMaxValue.Text = st.Max(s =&gt; s.flag).ToString();&lt;/div&gt;&lt;div&gt; LabelMin.Text=st.Min(s=&gt;s.flag).ToString();&lt;/div&gt;&lt;div&gt; LabelCount.Text = st.Count.ToString();&lt;/div&gt;&lt;div&gt; LabelSum.Text = st.Sum(s =&gt; s.flag).ToString();&lt;/div&gt;&lt;div&gt; LabelAverage.Text = st.Average(s =&gt; s.flag).ToString();&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here you can see like &lt;b&gt;s=&gt; s.flag&lt;/b&gt;.  This is a method showing the specific field we need to work on.&lt;/div&gt;&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;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/4852352982094431920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/4852352982094431920' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4852352982094431920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4852352982094431920'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/08/linq-to-objects-arithmetic-operations.html' title='Linq to Objects - Arithmetic Operations'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-5355832105679588144</id><published>2010-08-04T01:50:00.000-07:00</published><updated>2019-10-01T21:10:11.035-07:00</updated><title type='text'>How to Change Text of a Label inside a MasterPage from its inherited Page.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre style=&quot;background-color: #f4f4f4; border: 1px solid #DBDBDB; font-family: &#39;Courier New&#39; , Courier, monospace; margin-bottom: 10px; margin-top: 10px; padding: 10px;&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
((Label)this.Master.FindControl(&quot;Label1&quot;)).Text = &quot;Text to be changed&quot;;&lt;/div&gt;
&lt;/pre&gt;
&lt;br /&gt;
This code will find the control inside the Masterpage and Change it.

&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/5355832105679588144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/5355832105679588144' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/5355832105679588144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/5355832105679588144'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/08/how-to-change-text-of-label-inside.html' title='How to Change Text of a Label inside a MasterPage from its inherited Page.'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-493217985502134940</id><published>2010-07-28T01:43:00.000-07:00</published><updated>2010-07-28T02:10:14.143-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Entity Framework"/><title type='text'>ADO.NET Entity Framework</title><content type='html'>Create a EDM by adding a new ADO.NET Entity Data Model. Add your Database to it...&lt;br /&gt;&lt;br /&gt;Some terms used.....&lt;br /&gt;EDM -  Entity Data Model (Mapping Layer)&lt;br /&gt;CSDL - Conceptual Schema Definition Language (Conceptual Layer)&lt;br /&gt;SSDL - Stored Schema Definition Language (Logical Layer)&lt;br /&gt;&lt;br /&gt;Extension .edmx&lt;br /&gt;&lt;br /&gt;Codes after creating the EDM file....&lt;br /&gt;&lt;br /&gt;NationalBankModel.NationalBankEntities mm = new NationalBankModel.NationalBankEntities();&lt;br /&gt;        //var query = from n in mm.EmployeeDetails&lt;br /&gt;        //            select n;       &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        //var query = from n in mm.EmployeeDetails&lt;br /&gt;        //            where mm.Logins.Any(Emp =&gt; Emp.EmpID &gt;3)&lt;br /&gt;        //            select new {n.EmpID, n.EmpName, n.EmpAddress, n.EmpPhNo };&lt;br /&gt;&lt;br /&gt;        var query = from n in mm.EmployeeDetails&lt;br /&gt;                    //join oo in mm.Logins on n.EmpID equals oo.EmpID&lt;br /&gt;                    where mm.Logins.Any(Emp =&gt; Emp.EmpID == 3)&lt;br /&gt;                    //where n.EmpID &gt; 2&lt;br /&gt;                    select new { n.EmpID, n.EmpName, n.EmpAddress, n.EmpPhNo };&lt;br /&gt;&lt;br /&gt;GridView1.DataSource = query;&lt;br /&gt;        GridView1.DataBind();&lt;br /&gt;&lt;br /&gt;        foreach (var emp in mm.EmployeeDetails)&lt;br /&gt;        {&lt;br /&gt;            ListItem li = new ListItem();&lt;br /&gt;            li.Text = emp.EmpID + &quot; &quot;;&lt;br /&gt;            if (!emp.Logins.IsLoaded)&lt;br /&gt;            {&lt;br /&gt;                emp.Logins.Load();&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            foreach (var p in emp.Logins)&lt;br /&gt;            {&lt;br /&gt;                li.Text += &quot;Login Name: &quot; + p.username + &quot; &quot;;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            BulletedList1.Items.Add(li);&lt;br /&gt;        }</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/493217985502134940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/493217985502134940' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/493217985502134940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/493217985502134940'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/07/adonet-entity-framework.html' title='ADO.NET Entity Framework'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-1352652576181519808</id><published>2010-07-26T20:34:00.000-07:00</published><updated>2010-07-26T20:35:53.626-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Reporting"/><title type='text'>Custom Reporting using Crystalreports</title><content type='html'>Namespaces to use.&lt;br /&gt;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;using CrystalDecisions.CrystalReports.Engine;&lt;br /&gt;&lt;br /&gt;Code....&lt;br /&gt;SqlConnection con=new SqlConnection(@&quot;Data Source=.\sqlexpress;Initial Catalog=NationalBank;Integrated Security=True&quot;);&lt;br /&gt;        SqlDataAdapter da=new SqlDataAdapter(&quot;select * from EmployeeDetails where EMpname like &#39;g%&#39;&quot;,con);&lt;br /&gt;        &lt;br /&gt;        DataSet ds = new DataSet();&lt;br /&gt;        da.Fill(ds, &quot;d&quot;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        ReportDocument rpt = new ReportDocument();&lt;br /&gt;        rpt.Load(Server.MapPath(@&quot;~\CrystalReport.rpt&quot;));&lt;br /&gt;        rpt.SetDataSource(ds.Tables[&quot;d&quot;]);&lt;br /&gt;        CrystalReportViewer1.ReportSource = rpt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/1352652576181519808/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/1352652576181519808' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1352652576181519808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1352652576181519808'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/07/custom-reporting-using-crystalreports.html' title='Custom Reporting using Crystalreports'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-1624107107077965834</id><published>2010-07-15T05:01:00.000-07:00</published><updated>2010-12-16T02:18:47.146-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gridview"/><title type='text'>Taking index of a row in Gridview using RowCommand</title><content type='html'>For taking data using rowcommand property.... &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When you create the code of Gridview place the code like this for your customized Controls(Button)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;?xml:namespace prefix = asp /&gt;&lt;asp:button id=&quot;ButtonSubmit&quot; commandname=&quot;cmdSUBMIT&quot; text=&quot;Submit&quot; runat=&quot;server&quot;&gt;&lt;/asp:button&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&amp;ltasp:imagebutton id=&quot;imgProfile&quot; width=&quot;100px&quot; height=&quot;100px&quot; runat=&quot;server&quot; imageurl=&quot;&#39;&lt;%#&quot;&gt;&#39; CommandName=&quot;cmdImage&quot; CommandArgument=&#39;&amp;lt%# Container.DataItemIndex %&amp;gt&#39; /&amp;gt&lt;/div&gt;&lt;div&gt;Here look at the COmmand argument property it should be like this. Then only we can take the Index of the Gridview.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now, in Code behind you can call it like this....&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;string name = ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl(&quot;TextBoxName&quot;)).Text;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;thus you can work on it getting the index of the row.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/1624107107077965834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/1624107107077965834' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1624107107077965834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1624107107077965834'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/07/taking-index-of-row-in-gridview-using.html' title='Taking index of a row in Gridview using RowCommand'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-2567641991568447439</id><published>2010-07-15T04:59:00.000-07:00</published><updated>2010-07-15T05:00:30.941-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Gridview"/><title type='text'>Fetch data from Footer of Gridview</title><content type='html'>&lt;div&gt;Taking data from the Footer of a Gridview control in asp.net&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;   GridViewRow row = GridView1.FooterRow;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;   if (e.CommandName == &quot;cmdSUBMIT&quot;)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;   {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;     string name = ((TextBox)row.FindControl(&quot;TextBoxName&quot;)).Text;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;     Response.Write(name);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;   }&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/2567641991568447439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/2567641991568447439' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/2567641991568447439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/2567641991568447439'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2010/07/fetch-data-from-footer-of-gridview.html' title='Fetch data from Footer of Gridview'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-1566903730912178703</id><published>2009-07-28T00:08:00.000-07:00</published><updated>2009-07-28T00:16:55.362-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="WPF"/><title type='text'>Dock panel in WPF and Databinding</title><content type='html'>&amp;lt;DockPanel &amp;gt;&lt;br /&gt;        &amp;lt;TextBox DockPanel.Dock=&quot;Top&quot; Text=&quot;TOP&quot;/&amp;gt;&lt;br /&gt;        &amp;lt;TextBox DockPanel.Dock=&quot;Right&quot; Text=&quot;Right&quot;&amp;gt&amp;lt/TextBox&amp;gt;&lt;br /&gt;        &amp;l;tTextBox DockPanel.Dock=&quot;Bottom&quot; Text=&quot;{Binding Path=Name}&quot;/&amp;gt;&lt;br /&gt;    &amp;lt;/DockPanel&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-----------------------------------&lt;br /&gt; class person&lt;br /&gt;    {&lt;br /&gt;        string name = &quot;Admin&quot;;&lt;br /&gt;        public string Name&lt;br /&gt;        {&lt;br /&gt;            get { return name; }&lt;br /&gt;            set { name = value; }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;--------------------------------------&lt;br /&gt;public Window1()&lt;br /&gt;        {&lt;br /&gt;            InitializeComponent();&lt;br /&gt;            person p = new person();&lt;br /&gt;            this.DataContext = p;&lt;br /&gt;        }&lt;br /&gt;--------------------------------------</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/1566903730912178703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/1566903730912178703' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1566903730912178703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1566903730912178703'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2009/07/dock-panel-in-wpf-and-databinding.html' title='Dock panel in WPF and Databinding'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-4380851191034514700</id><published>2009-07-03T22:52:00.000-07:00</published><updated>2009-07-04T00:11:38.892-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GetElementID"/><category scheme="http://www.blogger.com/atom/ns#" term="Webbrowser"/><title type='text'>How to get Control ID&#39;s from websites using C# web browser</title><content type='html'>&lt;div&gt;ButtonGetID_Click&lt;/div&gt;&lt;div&gt;---------------&lt;/div&gt;&lt;div&gt;&lt;div&gt;MessageBox.Show(webBrowser1.Document.ActiveElement.Id.ToString());&lt;/div&gt;&lt;div&gt;----------------&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Insert data to the Fileds&lt;/div&gt;&lt;div&gt;--------------------------&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;            webBrowser1.Document.ActiveElement.InnerText = &quot;smilu&quot;;&lt;/div&gt;&lt;div&gt;            webBrowser1.Document.GetElementById(&quot;Passwd&quot;).InnerText = &quot;password&quot;;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;--------------------------&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Click in HTML Buttons&lt;/div&gt;&lt;div&gt;-----------------------------&lt;/div&gt;&lt;div&gt;&lt;div&gt;HtmlElement el = webBrowser1.Document.All[&quot;signIn&quot;];&lt;/div&gt;&lt;div&gt;            object obj = el.DomElement;&lt;/div&gt;&lt;div&gt;            System.Reflection.MethodInfo mi = obj.GetType().GetMethod(&quot;click&quot;);&lt;/div&gt;&lt;div&gt;            mi.Invoke(obj, new object[0]); &lt;/div&gt;&lt;/div&gt;&lt;div&gt;------------------------------&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/4380851191034514700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/4380851191034514700' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4380851191034514700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4380851191034514700'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2009/07/how-to-get-control-ids-from-websites.html' title='How to get Control ID&#39;s from websites using C# web browser'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-6948051530510544622</id><published>2009-02-21T00:15:00.000-08:00</published><updated>2009-07-05T22:27:43.880-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Encryption"/><title type='text'>String Encryption</title><content type='html'>&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;using System.Security.Cryptography;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;using System.IO;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;static string EncrypData;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;static byte[] bytes =System.Text.ASCIIEncoding.ASCII.GetBytes(&quot;AbCdEfGh&quot;);&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        private void buttonEncrypt_Click(object sender, EventArgs e)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                MemoryStream memoryStream = new MemoryStream();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                StreamWriter writer = new StreamWriter(cryptoStream);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                writer.Write(textBox1.Text);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                writer.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                cryptoStream.FlushFinalBlock();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                writer.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                EncrypData = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                StreamWriter sw = new StreamWriter(@&quot;C:\MyEncryption.DAT&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                sw.Write(EncrypData);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                sw.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                sw.Close();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            catch (Exception ex)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        private void buttonDecrypt_Click(object sender, EventArgs e)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(EncrypData));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Read);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                StreamReader reader = new StreamReader(cryptoStream);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                StreamWriter sw = new StreamWriter(@&quot;C:\MyDecrypt.DAT&quot;);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                sw.Write(reader.ReadToEnd());&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                sw.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                sw.Close();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            catch (Exception ex)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-family:&#39;courier new&#39;;&quot;&gt;        }&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/6948051530510544622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/6948051530510544622' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6948051530510544622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6948051530510544622'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2009/02/string-encryption.html' title='String Encryption'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-419085181144612413</id><published>2008-11-28T22:49:00.000-08:00</published><updated>2008-11-28T22:50:42.713-08:00</updated><title type='text'>Globalization</title><content type='html'>&lt;div&gt;using System.Globalization;&lt;/div&gt;&lt;div&gt;using System.Threading;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;switch (comboBox1.SelectedIndex)&lt;/div&gt;&lt;div&gt;            {&lt;/div&gt;&lt;div&gt;                case 0:&lt;/div&gt;&lt;div&gt;                    {&lt;/div&gt;&lt;div&gt;                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(&quot;ar-SA&quot;);&lt;/div&gt;&lt;div&gt;                        Form1 frm = new Form1();&lt;/div&gt;&lt;div&gt;                        frm.ShowDialog();&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;                        break;&lt;/div&gt;&lt;div&gt;                    }&lt;/div&gt;&lt;div&gt;                case 1:&lt;/div&gt;&lt;div&gt;                    {&lt;/div&gt;&lt;div&gt;                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(&quot;en-US&quot;);&lt;/div&gt;&lt;div&gt;                        Form1 frm = new Form1();&lt;/div&gt;&lt;div&gt;                        frm.ShowDialog();&lt;/div&gt;&lt;div&gt;                        break;&lt;/div&gt;&lt;div&gt;                    }&lt;/div&gt;&lt;div&gt;                case 2:&lt;/div&gt;&lt;div&gt;                    {&lt;/div&gt;&lt;div&gt;                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(&quot;hi-IN&quot;);&lt;/div&gt;&lt;div&gt;                        Form1 frm = new Form1();&lt;/div&gt;&lt;div&gt;                        frm.ShowDialog();&lt;/div&gt;&lt;div&gt;                        break;&lt;/div&gt;&lt;div&gt;                    }&lt;/div&gt;&lt;div&gt;                default:&lt;/div&gt;&lt;div&gt;                    {&lt;/div&gt;&lt;div&gt;                        Form1 frm = new Form1();&lt;/div&gt;&lt;div&gt;                        frm.ShowDialog();&lt;/div&gt;&lt;div&gt;                        break;&lt;/div&gt;&lt;div&gt;                    }&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/419085181144612413/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/419085181144612413' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/419085181144612413'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/419085181144612413'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2008/11/globalization.html' title='Globalization'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-1214029877577185607</id><published>2008-11-04T22:21:00.000-08:00</published><updated>2008-11-04T22:55:18.608-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CAS"/><title type='text'>Code Access Security</title><content type='html'>Code Access Security - Denying Read permission on C: drive&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;using System.Security.Permissions;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;[assembly:FileIOPermission(SecurityAction.RequestRefuse,Read=&quot;C:\\&quot;)]&lt;br /&gt;namespace CASS&lt;br /&gt;{&lt;br /&gt;    public partial class Form1 : Form&lt;br /&gt;    {&lt;br /&gt;        public Form1()&lt;br /&gt;        {&lt;br /&gt;            InitializeComponent();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private void button1_Click(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                StreamReader sr = new StreamReader(&quot;C:\\boot.ini&quot;);&lt;br /&gt;                MessageBox.Show(sr.ReadToEnd());&lt;br /&gt;                sr.Close();&lt;br /&gt;            }&lt;br /&gt;            catch (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                MessageBox.Show(ex.Message);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/1214029877577185607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/1214029877577185607' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1214029877577185607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/1214029877577185607'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2008/11/code-access-security.html' title='Code Access Security'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-5226019963723624974</id><published>2008-10-29T22:44:00.000-07:00</published><updated>2020-03-02T03:36:56.464-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Windows Service"/><title type='text'>How to create a simple Windows Service in C#..</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;&lt;i&gt;&lt;b&gt;With due permission from Saji P Babu i&#39;m writing this topic in my blog&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Windows Services are programs that can be started when the OS starts.... This will be running in the background of the Windows.&lt;br /&gt;
&lt;br /&gt;
In this i&#39;m just creating a simple windows service. For theory parts just refer some other sites...&lt;br /&gt;
&lt;br /&gt;
Here is the practical part.&lt;br /&gt;
&lt;br /&gt;
First we are going to create a Windows Service. For that&lt;br /&gt;
1) Open visual studio,&lt;br /&gt;
2) Take File menu --&amp;gt;New--&amp;gt;Project&lt;br /&gt;
3) From the list take a Windows service Application&lt;br /&gt;
&lt;br /&gt;
Now you&#39;ll be getting a form without a design with name &quot;projectIntaler.cs&quot;&lt;br /&gt;
&lt;br /&gt;
Next step is&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Right Click on the form and select AddInstaller&lt;/li&gt;
&lt;li&gt;Now you will get two Controls on the form&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;ProjectInstaller1&lt;/li&gt;
&lt;li&gt;serviceInstaller1&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
Take the Properties of projectInstaller1&lt;br /&gt;
--Set account to LocalSystem&lt;br /&gt;
&lt;br /&gt;
now, take the properties or serviceInstaller1, there are three properties you must set&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Start Type&lt;/li&gt;
&lt;li&gt;Service name and&lt;/li&gt;
&lt;li&gt;Display Name&lt;/li&gt;
&lt;/ul&gt;
Start type refers to how one must start this service.&lt;br /&gt;
Service name refers to the name to be shown in the Process List and,&lt;br /&gt;
Display name is the name that will be displayed inside the Services list....&lt;br /&gt;
&lt;br /&gt;
Now set Start type to &quot;Automatic&quot;,&lt;br /&gt;
ServiceName to &quot;someName&quot; and&lt;br /&gt;
DisplayName to &quot;dispName&quot;&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------&lt;br /&gt;
Now take Service1.cs .&lt;br /&gt;
In this file we will be adding controls... Inside this we can only add controls form inside the Command tab. This will not show any design of the controls... More will be background controls&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So we will just check a FileSystemWatcher control.&lt;br /&gt;
FileSystemWatcher is a control through which we can monitor an entire drive...&lt;br /&gt;
&lt;br /&gt;
Add a fileSystemWatcher to it.&lt;br /&gt;
Now take the properties of fileSystemWatcher Set the path to the Folder or the Drive you need to Monitor...&lt;br /&gt;
Set EnableRaisingEvents to true...&lt;br /&gt;
IncludeSubDirectories to True.&lt;br /&gt;
&lt;br /&gt;
There is an option also called notify Filter you can set it to anything you need.&lt;br /&gt;
&lt;br /&gt;
Now take the Events of the FileSystemWatcher by clicking the Event tab in the Properties window...&lt;br /&gt;
Double click on the &quot;created&quot; event so that you get the fileSystemWatcher1_Created event.&lt;br /&gt;
&lt;br /&gt;
now inside the event write these codes&lt;br /&gt;
&lt;br /&gt;
-------------------------&lt;br /&gt;
System.IO.StreamWriter sw = new System.IO.StreamWriter(@&quot;C:\sm.txt&quot;, true);&lt;br /&gt;
sw.WriteLine(e.ChangeType + &quot; &quot; + e.FullPath);&lt;br /&gt;
sw.Flush();&lt;br /&gt;
sw.Close();&lt;br /&gt;
-------------------------&lt;br /&gt;
This will create a file when there is change in the directory we have selected.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So now you have created a windows service... This cannot be executed directly. So we must install this service to our machine and start it.&lt;br /&gt;
So, First of all Build the solution... now we must install it..&lt;br /&gt;
For that Take the VisualStudio Command Prompt&lt;br /&gt;
Inside it navigate to the folder inside which we have created the service.&lt;br /&gt;
Now goto the debug folder ...&lt;br /&gt;
eg: the path will be like this&lt;br /&gt;
&lt;br /&gt;
D:\Smilu\windowService\bin\debug&amp;gt;&lt;br /&gt;
&lt;br /&gt;
now if you are inside the debug folder you can see the .exe files of your service that we need to install&lt;br /&gt;
&lt;br /&gt;
For installing it type the command like this&lt;br /&gt;
&lt;br /&gt;
installutil /i smilu.exe&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;/i - will install the service&lt;/li&gt;
&lt;li&gt;/u - will unistall the service&lt;/li&gt;
&lt;/ul&gt;
-------------------------&lt;br /&gt;
D:\Smilu\windowService\bin\Debug&amp;gt;installutil /i smilu.exe&lt;br /&gt;
-------------------------&lt;br /&gt;
Here smilu.exe is the service name.&lt;br /&gt;
&lt;br /&gt;
Now restart the machine... The service gets automatically started when we starts the windows.&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
Go to the control panel--&amp;gt;Administrative Tools--&amp;gt;services&lt;br /&gt;
Inside it there will be your service listed...&lt;br /&gt;
Right click on it and start the service...&lt;br /&gt;
&lt;br /&gt;
Now create a file in the Directory you have mentioned for fileSystemWatcher..&lt;br /&gt;
and see the new file created with sm.txt in C:\.&lt;br /&gt;
This windows service will not be shown anywhere... It&#39;ll  be working in the back ground as a process.....&lt;br /&gt;
To see this process Take TaskManager and see the Process tab inside it....&lt;br /&gt;
You can see the Process inside it.....&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now The most important thing... If you need to modify the WindowsService you first need to Uninstall the service and only after that you should create it or install it...&lt;br /&gt;
&lt;br /&gt;
for unistalling it you can use&lt;br /&gt;
&lt;br /&gt;
installutil /u smilu.exe&lt;br /&gt;
&lt;br /&gt;
If you install a service already running it may cause upto a System crash on your machine...&lt;br /&gt;
&lt;br /&gt;
The steps should be the exact cycle like this&lt;br /&gt;
&lt;br /&gt;
1) Create a Windows Service&lt;br /&gt;
2) Install a Windows Service and use it&lt;br /&gt;
and now if u need to modify&lt;br /&gt;
1)  Uninstall the running service..&lt;br /&gt;
2) Build the service&lt;br /&gt;
3) Install it again&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------------------------------&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/5226019963723624974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/5226019963723624974' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/5226019963723624974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/5226019963723624974'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2008/10/how-to-create-simple-windows-service-in.html' title='How to create a simple Windows Service in C#..'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-2776732778328000805</id><published>2008-10-28T00:05:00.000-07:00</published><updated>2008-10-28T00:09:21.236-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="String to Dataset"/><title type='text'>Converting XML String to a Dataset in C#</title><content type='html'>using System.IO;              &lt;br /&gt;&lt;br /&gt;//Event&lt;br /&gt;string a=gwObj.GetCitiesByCountry(&quot;India&quot;);  //This returns an xml string&lt;br /&gt;              StringReader sr = new System.IO.StringReader(a);&lt;br /&gt;              DataSet ds = new DataSet();&lt;br /&gt;              ds.ReadXml(sr);&lt;br /&gt;              dataGridView1.DataSource = ds.Tables[0];&lt;br /&gt;             &lt;br /&gt;comboBox1.DataSource = ds.Tables[0];&lt;br /&gt;              comboBox1.DisplayMember = &quot;City&quot;;&lt;br /&gt;&lt;br /&gt;this program displays the city inside the combo box</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/2776732778328000805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/2776732778328000805' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/2776732778328000805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/2776732778328000805'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2008/10/converting-xml-string-to-dataset-in-c.html' title='Converting XML String to a Dataset in C#'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-6243067541154723593</id><published>2008-07-30T20:34:00.000-07:00</published><updated>2008-07-30T20:36:16.942-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hashing"/><title type='text'>C# Hashing</title><content type='html'>using System.Security.Cryptography;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; UnicodeEncoding ue = new UnicodeEncoding();&lt;br /&gt;        private void button1_Click(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            byte[] plaintext = ue.GetBytes(TextBoxplaintxt.Text);&lt;br /&gt;            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();&lt;br /&gt;            byte[] hash = md5.ComputeHash(plaintext);&lt;br /&gt;            TextBoxHashed.Text = Convert.ToBase64String(hash);&lt;br /&gt;        }</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/6243067541154723593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/6243067541154723593' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6243067541154723593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/6243067541154723593'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2008/07/c-hashing.html' title='C# Hashing'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-4163868396121047847</id><published>2008-07-30T02:59:00.000-07:00</published><updated>2008-07-30T03:02:41.244-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Decryptions"/><category scheme="http://www.blogger.com/atom/ns#" term="Encryption"/><title type='text'>Encryption and Decryption in C#</title><content type='html'>&lt;span style=&quot;font-family:courier new;&quot;&gt;using System.IO;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;using System.Security;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;using System.Security.Cryptography;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;string passValue;&lt;br /&gt;private void EncryptButton_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;passValue = textBox1.Text;&lt;br /&gt;RandomNumberGenerator rnd = RandomNumberGenerator.Create();&lt;br /&gt;byte[] salt = new byte[16];&lt;br /&gt;rnd.GetBytes(salt);&lt;br /&gt;Rfc2898DeriveBytes derBytes = new Rfc2898DeriveBytes(passValue, salt);&lt;br /&gt;byte[] key = derBytes.GetBytes(16);&lt;br /&gt;Rijndael cryptoAlg = Rijndael.Create();&lt;br /&gt;cryptoAlg.Key = key;&lt;br /&gt;FileStream fs = new FileStream(@&quot;C:\Hello\EncryptPass.txt&quot;, FileMode.Create);&lt;br /&gt;fs.Write(salt, 0, salt.Length);&lt;br /&gt;fs.Write(cryptoAlg.IV, 0, cryptoAlg.IV.Length);&lt;br /&gt;CryptoStream cryptStream = new CryptoStream(fs, cryptoAlg.CreateEncryptor(), CryptoStreamMode.Write);&lt;br /&gt;//Converting a string to an byte array&lt;br /&gt;byte[] ar = System.Text.Encoding.UTF8.GetBytes(passValue);&lt;br /&gt;cryptStream.Write(ar, 0, ar.Length);&lt;br /&gt;cryptStream.FlushFinalBlock();&lt;br /&gt;cryptStream.Close();&lt;br /&gt;MessageBox.Show(&quot;Data Encrypted&quot;);&lt;br /&gt;}&lt;br /&gt;catch (Exception ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show(ex.Message);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;private void DecryptButton_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Rijndael deCryptoAlg = Rijndael.Create();&lt;br /&gt;FileStream fs3 = new FileStream(@&quot;C:\Hello\DecryptPass.txt&quot;, FileMode.OpenOrCreate);&lt;br /&gt;FileStream fs2 = new FileStream(@&quot;C:\Hello\EncryptPass.txt&quot;, FileMode.Open);&lt;br /&gt;byte[] salt = new byte[16];&lt;br /&gt;byte[] IV = new byte[deCryptoAlg.IV.Length];&lt;br /&gt;fs2.Read(salt, 0, salt.Length);&lt;br /&gt;fs2.Read(IV, 0, IV.Length);&lt;br /&gt;Rfc2898DeriveBytes derByte = new Rfc2898DeriveBytes(passValue, salt);&lt;br /&gt;byte[] key = derByte.GetBytes(16);&lt;br /&gt;deCryptoAlg.Key = key;&lt;br /&gt;deCryptoAlg.IV = IV;&lt;br /&gt;CryptoStream cryStream = new CryptoStream(fs2, deCryptoAlg.CreateDecryptor(), CryptoStreamMode.Read);&lt;br /&gt;int bytesRead = 0;&lt;br /&gt;byte[] buffer = new byte[256];&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;bytesRead = cryStream.Read(buffer, 0, 256);&lt;br /&gt;} while (bytesRead &gt; 0);&lt;br /&gt;fs3.Write(buffer, 0, 256);&lt;br /&gt;fs3.Flush();&lt;br /&gt;cryStream.Close();&lt;br /&gt;MessageBox.Show(&quot;File Decrypted&quot;);&lt;br /&gt;}&lt;br /&gt;catch (Exception ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show(ex.Message);&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/4163868396121047847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/4163868396121047847' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4163868396121047847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/4163868396121047847'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2008/07/encryption-and-decryption-in-c.html' title='Encryption and Decryption in C#'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-7581746778320297237</id><published>2008-05-14T22:25:00.000-07:00</published><updated>2008-05-14T22:42:49.540-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="ASP.net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="Transaction"/><title type='text'>SQL Transactions in .net</title><content type='html'>&lt;span style=&quot;font-family: courier new;&quot;&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;SqlTransaction is used in cases we are updating Multiple tables at a Time. Here the error occurs such as first table gets updated and the next table which have a relation with the first table does not get Updated due to some Errors may be some Power Failure etc.... So to overcome these types of errors we can use SqlTransaction in the programs.....&lt;br /&gt;&lt;br /&gt;Here is an example for the SqlTransaction&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;public partial class Form1 : Form&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        SqlConnection con = new SqlConnection(@&quot;Integrated Security=SSPI;Initial Catalog=NationalBank;Data Source=.\SQLEXPRESS&quot;);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        SqlCommand cmd;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;Here you are going to make an Object for SqlTransaction named sqtr&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        SqlTransaction sqtr;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        public Form1()&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            InitializeComponent();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            con.Open();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        private void button1_Click(object sender, EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        {&lt;br /&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;The below step starts the transaction&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            sqtr = con.BeginTransaction();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            try&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                eNameInsert(txtName.Text);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                eAddressInsert(txtPassword.Text);&lt;br /&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;If the transaction completes successfully the commit method is called.....&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                sqtr.Commit();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            catch (Exception ex)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            {&lt;br /&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;The rollback method of the SqlTransaction Undos all the things which have been updated if an Error occurs&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                sqtr.Rollback();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        static int i;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        private void eNameInsert(string Name)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            try&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            {&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: arial;&quot;&gt;We must mention the SqlTransaction object name after the con with  each SqlCommand&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd = new SqlCommand(&quot;Insert into eName values(@eName)&quot;, con,sqtr);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd.Parameters.AddWithValue(&quot;@eName&quot;, Name);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd.ExecuteNonQuery();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd = new SqlCommand(&quot;Select EId from eName where EName=&#39;&quot; + Name + &quot;&#39;&quot;, con,sqtr);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                i = Convert.ToInt32(cmd.ExecuteScalar());&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            catch (SqlException ex)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                sqtr.Rollback();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        private void eAddressInsert(string Address)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            try&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd = new SqlCommand(&quot;Insert into eAddress values(@id,@eAddress)&quot;, con,sqtr);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd.Parameters.AddWithValue(&quot;@eAddress&quot;, Address);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd.Parameters.AddWithValue(&quot;@id&quot;, i);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                cmd.ExecuteNonQuery();&lt;br /&gt;sqtr.Commit();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            catch (SqlException ex)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                sqtr.Rollback();&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: courier new;&quot;&gt;        }&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://csharp-asp.blogspot.com/feeds/7581746778320297237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2288766597779679530/7581746778320297237' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/7581746778320297237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2288766597779679530/posts/default/7581746778320297237'/><link rel='alternate' type='text/html' href='http://csharp-asp.blogspot.com/2008/05/sql-transactions-in-net.html' title='SQL Transactions in .net'/><author><name>Smilu Varghese</name><uri>http://www.blogger.com/profile/04307798472439170075</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>