<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' 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>2011-11-27T15:19:17.252-08:00</updated><category term='Reporting'/><category term='C#'/><category term='Gridview'/><category term='SQL'/><category term='Linq to Objects'/><category term='Linq'/><category term='XLinq'/><category term='Insertion'/><category term='.net'/><category term='Decryptions'/><category term='XML'/><category term='Encryption'/><category term='Windows Service'/><category term='Hashing'/><category term='GetElementID'/><category term='Webbrowser'/><category term='WPF'/><category term='Transaction'/><category term='ASP.net'/><category term='Entity Framework'/><category term='String to Dataset'/><category term='Report Viewer'/><category term='CAS'/><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?max-results=100'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>22</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2288766597779679530.post-8511761166520439777</id><published>2011-11-23T01:20:00.000-08:00</published><updated>2011-11-23T01:23:57.254-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Reporting'/><category scheme='http://www.blogger.com/atom/ns#' term='Report Viewer'/><title type='text'>Dynamically create a Report in ReportViewer</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&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="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-fTdvrDHYrSU/TsyyHgMOkbI/AAAAAAAACME/XdcUUYZjLxQ/s1600/createreport.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="205" src="http://4.bp.blogspot.com/-fTdvrDHYrSU/TsyyHgMOkbI/AAAAAAAACME/XdcUUYZjLxQ/s320/createreport.png" width="320" /&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="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-VjA3NkNO168/TsyyUdmihAI/AAAAAAAACMM/zg1teS7aJZU/s1600/selectDataSource.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="249" src="http://4.bp.blogspot.com/-VjA3NkNO168/TsyyUdmihAI/AAAAAAAACMM/zg1teS7aJZU/s320/selectDataSource.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;The dataset will be diplayed in the report data window.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Hk5wZn7WrVs/TsyyyPDhxAI/AAAAAAAACMU/bolHxbM5a8o/s1600/SelectDataset.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="417" src="http://2.bp.blogspot.com/-Hk5wZn7WrVs/TsyyyPDhxAI/AAAAAAAACMU/bolHxbM5a8o/s640/SelectDataset.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&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="separator" style="clear: both; text-align: left;"&gt;Select the DataTable you created in the Dataset in the AvailableDatasets section and click OK.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Now, You will get the information in the left pane window.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ww6Rdm0GJ3c/TsyzubAmYjI/AAAAAAAACMc/BWHTQuxMKoY/s1600/datasetCreated.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-ww6Rdm0GJ3c/TsyzubAmYjI/AAAAAAAACMc/BWHTQuxMKoY/s400/datasetCreated.png" width="257" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&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="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&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="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-v0wGYNLQzHg/Tsy1wEm2m-I/AAAAAAAACMk/Uu6GiARPwA8/s1600/table.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="348" src="http://3.bp.blogspot.com/-v0wGYNLQzHg/Tsy1wEm2m-I/AAAAAAAACMk/Uu6GiARPwA8/s400/table.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-zg_GsEAO8Z0/Tsy1_rPR7cI/AAAAAAAACMs/xngaY-52JGs/s1600/bindtoTable.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="147" src="http://2.bp.blogspot.com/-zg_GsEAO8Z0/Tsy1_rPR7cI/AAAAAAAACMs/xngaY-52JGs/s400/bindtoTable.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&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="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-9_igQoqr1U4/Tsy2n3geRTI/AAAAAAAACM0/40DNQyCzS7w/s1600/selectRDLF.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-9_igQoqr1U4/Tsy2n3geRTI/AAAAAAAACM0/40DNQyCzS7w/s1600/selectRDLF.png" /&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;ltrsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Font-Size="8pt" InteractiveDeviceInfos="(Collection)"&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="651px"&amp;rt&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;ltLocalReport ReportPath="rerportsmilu.rdlc"&amp;rt&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;ltDataSources&amp;rt&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&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white;"&gt;&amp;nbsp;rsweb:ReportDataSource / &amp;rt&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;rt&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt/LocalReport&amp;rt&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt/rsweb:ReportViewer&amp;rt&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="Apple-style-span" style="color: blue;"&gt;using &lt;/span&gt;System.Data.SqlClient;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue;"&gt;using &lt;/span&gt;Microsoft.Reporting.WebForms;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: blue;"&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="Apple-style-span" style="color: #3d85c6;"&gt;smiluDS &lt;/span&gt;tDs = new &lt;span class="Apple-style-span" style="color: #3d85c6;"&gt;smiluDS&lt;/span&gt;();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: #6fa8dc;"&gt;SqlConnection &lt;/span&gt;con = &lt;span class="Apple-style-span" style="color: blue;"&gt;new &lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #3d85c6;"&gt;SqlConnection&lt;/span&gt;(WebConfigurationManager.ConnectionStrings["NationalBankConnectionString"].ConnectionString);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #6fa8dc;"&gt;SqlDataAdapter &lt;/span&gt;&lt;/span&gt;da = new &lt;span class="Apple-style-span" style="color: #6fa8dc;"&gt;SqlDataAdapter&lt;/span&gt;("Select * from Employee", 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="Apple-style-span" style="background-color: white;"&gt;&lt;span class="Apple-style-span" style="color: #3d85c6;"&gt;ReportDataSource &lt;/span&gt;&lt;/span&gt;rDs = new &lt;span class="Apple-style-span" style="color: #3d85c6;"&gt;ReportDataSource&lt;/span&gt;("&lt;span class="Apple-style-span" style="color: #cc0000;"&gt;DataSetSmilu&lt;/span&gt;", 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="Apple-style-span" style="color: #3d85c6;"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-8511761166520439777?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=8511761166520439777' title='0 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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-fTdvrDHYrSU/TsyyHgMOkbI/AAAAAAAACME/XdcUUYZjLxQ/s72-c/createreport.png' height='72' width='72'/><thr:total>0</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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-5447325971282310958?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&gt;</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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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='Insertion'/><category scheme='http://www.blogger.com/atom/ns#' term='Entity Framework'/><title type='text'>Insertion Using Entity Model</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_EWCQ9NzjkT4/THyrlwNR7QI/AAAAAAAAAQg/Yby6-eF_r3o/s1600/Nation.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 240px; height: 230px;" src="http://3.bp.blogspot.com/_EWCQ9NzjkT4/THyrlwNR7QI/AAAAAAAAAQg/Yby6-eF_r3o/s320/Nation.JPG" border="0" alt="" id="BLOGGER_PHOTO_ID_5511468709078756610" /&gt;&lt;/a&gt;&lt;div style="text-align: center;"&gt;&lt;span class="Apple-style-span"  style="color:#0000EE;"&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_EWCQ9NzjkT4/THyrlwNR7QI/AAAAAAAAAQg/Yby6-eF_r3o/s1600/Nation.JPG"&gt;&lt;/a&gt;&lt;span class="Apple-style-span"  style="color:#0000EE;"&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="text-align: left;"&gt;We are going to  add Items into the table EmployeeDetail&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;Now we must write the code like below&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: left;"&gt;NationalBankModel3.NationalBankEntities3 m = new NationalBankModel3.NationalBankEntities3();&lt;/div&gt;&lt;div style="text-align: left;"&gt;        NationalBankModel3.EmployeeDetail Emp = new NationalBankModel3.EmployeeDetail() { EmpName = "Smilu", EmpAddress = "EKM", EmpPhNo = "987654", EmpDob =Convert.ToDateTime("01/01/01") };&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;        m.AddToEmployeeDetails(Emp);&lt;/div&gt;&lt;div style="text-align: left;"&gt;        m.SaveChanges();&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;Here AddToEmployeeDetails will be the method which will insert the data of the Entity we send.&lt;/div&gt;&lt;div style="text-align: left;"&gt;SaveChages() will store the data into the table&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-9073944652966954294?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_EWCQ9NzjkT4/THyrlwNR7QI/AAAAAAAAAQg/Yby6-eF_r3o/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='XLinq'/><category scheme='http://www.blogger.com/atom/ns#' term='Linq'/><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="http://csharp-asp.blogspot.com/2010/08/studentsxml-file.html"&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("Students.xml")).Elements("Student1")&lt;/div&gt;&lt;div&gt;                    select new&lt;/div&gt;&lt;div&gt;                    {&lt;/div&gt;&lt;div&gt;                        Name = (string)s.Element("StName"),&lt;/div&gt;&lt;div&gt;                        Address = (string)s.Element("StAddress"),&lt;/div&gt;&lt;div&gt;                        PhNo = (string)s.Element("StPHNO"),&lt;/div&gt;&lt;div&gt;                        flag = (int)s.Element("Flag")&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("StName")&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-4846680276707400981?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-6360003109798558386?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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="Smilu",Address="EKM",PhNo="987654",flag=1},&lt;/div&gt;&lt;div&gt;            new Student{Name="JK", Address="Parur",PhNo="897643",flag=0},&lt;/div&gt;&lt;div&gt;            new Student{Name="Kiran", Address="EKM",PhNo="798654",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="CS"},&lt;/div&gt;&lt;div&gt;            new FlagName{flagID=1,flagName="Network"}&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 "mystudents" and "flags" 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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-6409076916782413304?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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="Apple-style-span"  style="font-family:'courier new';"&gt;public List&lt;student&gt; GetStudents()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;    {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        return new List&lt;student&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            new Student{Name="Smilu",Address="EKM",PhNo="987654",flag=1},&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            new Student{Name="JK", Address="Parur",PhNo="897643",flag=0},&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            new Student{Name="Binu", Address="EKM",PhNo="798654",flag=1}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        };&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;    }&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;--------------------------------------------------&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-4852352982094431920?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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>2010-08-04T01:53:22.580-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;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;((Label)this.Master.FindControl("Label1")).Text = "Text to be changed";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code will find the control inside the Masterpage and Change it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-5355832105679588144?l=csharp-asp.blogspot.com' alt='' /&gt;&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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 + " ";&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 += "Login Name: " + p.username + " ";&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            BulletedList1.Items.Add(li);&lt;br /&gt;        }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-493217985502134940?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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(@"Data Source=.\sqlexpress;Initial Catalog=NationalBank;Integrated Security=True");&lt;br /&gt;        SqlDataAdapter da=new SqlDataAdapter("select * from EmployeeDetails where EMpname like 'g%'",con);&lt;br /&gt;        &lt;br /&gt;        DataSet ds = new DataSet();&lt;br /&gt;        da.Fill(ds, "d");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        ReportDocument rpt = new ReportDocument();&lt;br /&gt;        rpt.Load(Server.MapPath(@"~\CrystalReport.rpt"));&lt;br /&gt;        rpt.SetDataSource(ds.Tables["d"]);&lt;br /&gt;        CrystalReportViewer1.ReportSource = rpt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-1352652576181519808?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&gt;</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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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="ButtonSubmit" commandname="cmdSUBMIT" text="Submit" runat="server"&gt;&lt;/asp:button&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&amp;ltasp:imagebutton id="imgProfile" width="100px" height="100px" runat="server" imageurl="'&lt;%#"&gt;' CommandName="cmdImage" CommandArgument='&amp;lt%# Container.DataItemIndex %&amp;gt' /&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("TextBoxName")).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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-1624107107077965834?l=csharp-asp.blogspot.com' alt='' /&gt;&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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="Apple-style-span"  style="font-family:'courier new';"&gt;   GridViewRow row = GridView1.FooterRow;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;   if (e.CommandName == "cmdSUBMIT")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;   {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;     string name = ((TextBox)row.FindControl("TextBoxName")).Text;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;     Response.Write(name);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;   }&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-2567641991568447439?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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="Top" Text="TOP"/&amp;gt;&lt;br /&gt;        &amp;lt;TextBox DockPanel.Dock="Right" Text="Right"&amp;gt&amp;lt/TextBox&amp;gt;&lt;br /&gt;        &amp;l;tTextBox DockPanel.Dock="Bottom" Text="{Binding Path=Name}"/&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 = "Admin";&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;--------------------------------------&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-1566903730912178703?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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'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 = "smilu";&lt;/div&gt;&lt;div&gt;            webBrowser1.Document.GetElementById("Passwd").InnerText = "password";&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["signIn"];&lt;/div&gt;&lt;div&gt;            object obj = el.DomElement;&lt;/div&gt;&lt;div&gt;            System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-4380851191034514700?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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&apos;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='http://img2.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="Apple-style-span"  style="font-family:'courier new';"&gt;using System.Security.Cryptography;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;using System.IO;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;static string EncrypData;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;static byte[] bytes =System.Text.ASCIIEncoding.ASCII.GetBytes("AbCdEfGh");&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        private void buttonEncrypt_Click(object sender, EventArgs e)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                MemoryStream memoryStream = new MemoryStream();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                StreamWriter writer = new StreamWriter(cryptoStream);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                writer.Write(textBox1.Text);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                writer.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                cryptoStream.FlushFinalBlock();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                writer.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                EncrypData = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                StreamWriter sw = new StreamWriter(@"C:\MyEncryption.DAT");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                sw.Write(EncrypData);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                sw.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                sw.Close();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            catch (Exception ex)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        private void buttonDecrypt_Click(object sender, EventArgs e)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            try&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(EncrypData));&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Read);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                StreamReader reader = new StreamReader(cryptoStream);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                StreamWriter sw = new StreamWriter(@"C:\MyDecrypt.DAT");&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                sw.Write(reader.ReadToEnd());&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                sw.Flush();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                sw.Close();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            catch (Exception ex)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            {&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;            }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;        }&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-6948051530510544622?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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("ar-SA");&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("en-US");&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("hi-IN");&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-419085181144612413?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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="C:\\")]&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("C:\\boot.ini");&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;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-1214029877577185607?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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>2008-10-30T01:45:20.883-07: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&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 255, 51);"&gt;With due permission from Saji P Babu i'm writing this topic in my blog&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'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 --&gt;New--&gt;Project&lt;br /&gt;3) From the list take a Windows service Application&lt;br /&gt;&lt;br /&gt;   Now you'll be getting a form without a design with name "projectIntaler.cs"&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 "Automatic",&lt;br /&gt;ServiceName to "someName" and&lt;br /&gt;DisplayName to "dispName"&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 "created" 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(@"C:\sm.txt", true);&lt;br /&gt;           sw.WriteLine(e.ChangeType + " " + 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&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;br /&gt;&lt;/li&gt;&lt;/ul&gt;-------------------------&lt;br /&gt;D:\Smilu\windowService\bin\Debug&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--&gt;Administrative Tools--&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'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 class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-5226019963723624974?l=csharp-asp.blogspot.com' alt='' /&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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("India");  //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 = "City";&lt;br /&gt;&lt;br /&gt;this program displays the city inside the combo box&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-2776732778328000805?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&gt;</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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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;        }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-6243067541154723593?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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='Encryption'/><category scheme='http://www.blogger.com/atom/ns#' term='Decryptions'/><title type='text'>Encryption and Decryption in C#</title><content type='html'>&lt;span style="font-family:courier new;"&gt;using System.IO;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;using System.Security;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;using System.Security.Cryptography;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&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(@"C:\Hello\EncryptPass.txt", 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("Data Encrypted");&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(@"C:\Hello\DecryptPass.txt", FileMode.OpenOrCreate);&lt;br /&gt;FileStream fs2 = new FileStream(@"C:\Hello\EncryptPass.txt", 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("File Decrypted");&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-4163868396121047847?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.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='ASP.net'/><category scheme='http://www.blogger.com/atom/ns#' term='.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="font-family: courier new;"&gt;&lt;span style="font-family: arial;"&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="font-family: courier new;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        SqlConnection con = new SqlConnection(@"Integrated Security=SSPI;Initial Catalog=NationalBank;Data Source=.\SQLEXPRESS");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        SqlCommand cmd;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&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="font-family: courier new;"&gt;        SqlTransaction sqtr;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        public Form1()&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            InitializeComponent();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            con.Open();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        private void button1_Click(object sender, EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        {&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The below step starts the transaction&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;            sqtr = con.BeginTransaction();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                eNameInsert(txtName.Text);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                eAddressInsert(txtPassword.Text);&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If the transaction completes successfully the commit method is called.....&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;                sqtr.Commit();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            catch (Exception ex)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            {&lt;br /&gt;&lt;span style="font-family: arial;"&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="font-family: courier new;"&gt;                sqtr.Rollback();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        static int i;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        private void eNameInsert(string Name)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            {&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&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="font-family: courier new;"&gt;                cmd = new SqlCommand("Insert into eName values(@eName)", con,sqtr);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cmd.Parameters.AddWithValue("@eName", Name);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cmd.ExecuteNonQuery();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cmd = new SqlCommand("Select EId from eName where EName='" + Name + "'", con,sqtr);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                i = Convert.ToInt32(cmd.ExecuteScalar());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            catch (SqlException ex)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                sqtr.Rollback();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        private void eAddressInsert(string Address)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            try&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cmd = new SqlCommand("Insert into eAddress values(@id,@eAddress)", con,sqtr);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cmd.Parameters.AddWithValue("@eAddress", Address);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cmd.Parameters.AddWithValue("@id", i);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                cmd.ExecuteNonQuery();&lt;br /&gt;sqtr.Commit();&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            catch (SqlException ex)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                sqtr.Rollback();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;                MessageBox.Show(ex.Message);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;            }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        }&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2288766597779679530-7581746778320297237?l=csharp-asp.blogspot.com' alt='' /&gt;&lt;/div&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.g?blogID=2288766597779679530&amp;postID=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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
