Skip to main content

Posts

Showing posts from 2012

Check folder and Delete All Files from Existing Folder in C#

Dynamically check the Particular name Folder exist or not, it not exits create folder dynamically. if (!Directory.Exists(FolderName))         {             Directory.CreateDirectory(FolderName);         }         if (Directory.Exists(FolderName))         {             string[] filePaths = Directory.GetFiles(FolderName);             foreach (string filePath in filePaths)                 File.Delete(filePath);             //Directory.Delete(FolderName);                    }

Sorting the Data in Grid view Manually.

Session["SortTable"] = table; //From Which table  data you are going to bind in gridview  keep that table data in session. protected void gvtest_Sorting1(object sender, GridViewSortEventArgs e)     {         try         {             GridView grid = (GridView)sender;             ViewState["sortexpression"] = e.SortExpression;             if (ViewState["sortdirection"] == null)             {                 ViewState["sortdirection"] = "asc";             }             else             {                 if (ViewState["sortdirection"].ToString() == "asc")                 {                     ViewState["sortdirection"] = "desc";                 }                 else                 {                     ViewState["sortdirection"] = "asc";                 }             }             DataTable dtLive = (DataTable)Session["SortTable "];             DataView dv = dtLive.D

Convert LinQ to Datable in C#

Var List= From Tolist(); DataTable table = LINQToDataTable(List);//You will get DataTable Value public DataTable LINQToDataTable<T>(IEnumerable<T> varlist)     {        DataTable dtReturn = new DataTable();        dtReturn.Clear();         // column names         PropertyInfo[] oProps = null;         if (varlist == null) return dtReturn;         foreach (T rec in varlist)         {             if (oProps == null)             {                 oProps = ((Type)rec.GetType()).GetProperties();                 foreach (PropertyInfo pi in oProps)                 {                     Type colType = pi.PropertyType;                     if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))                     {                         colType = colType.GetGenericArguments()[0];                     }                     dtReturn.Columns.Add(new DataColumn(pi.Name, colType));                 }            

Create and send HTML Formatted Emails in ASP.Net using C#

Create File name as Test.htm <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title></title> </head> <body>     <img src="/Logo.png" /><br />     <br />     <div style="border-top: 3px solid #22BCE5">         &nbsp;</div>     <span style="font-family: Arial; font-size: 10pt">Hello <b>{UserName}</b>,<br />         <br />         A new article has been published on ASPSnippets.<br />         <br />         <a style="color: #22BCE5" href="{Url}">{Title}</a><br />         {Description}         <br />         <br />         Thanks<br />         Raghu.N </span> </body> </html> Note :- While Creating Mail Format Body….Follow this logic or else do your own Logic Style. private string PopulateBody(string userName, string title, string url, string description)     {

Linq Query Using Left Joins With AsEnumerable()

var qu = (from tt in table1.AsEnumerable()  join ss in table2.AsEnumerable()                      on tt.Field<int>("UniqID")    equals ss.Field<int>(" UniqID ")                                                   into tt_ss                      from ss in tt_ss.DefaultIfEmpty()                      select new                      {                          FirstName = tt.Field<string>("ColumnsFName"),                          LastName = ss.Field<string>("ColumnsLName"),                          FileName = ss == null ? "" : ss.Field<string>("FileName"),                        }).ToList();

Linq Query Using Joins with AsEnumerable()

var qu = (from tt in table1.AsEnumerable()           join ss in table2.AsEnumerable() on tt.Field<int>("UniqID")       equals ss.Field<int>(" UniqID ")                                        select new             {               FirstName = tt.Field<string>("ColumnsFName"),               LastName = ss.Field<string>("ColumnsLName"),             }).ToList(); Note:- Using Left join we should check   null rows in the second table. If have null row it`s throw error without   check null rows in second table.

Add SpacesTo Sentence in C#

 public string AddSpacesToSentence(string text)     {         if (string.IsNullOrEmpty(text))             return "";         StringBuilder newText = new StringBuilder(text.Length * 2);         newText.Append(text[0]);         for (int i = 1; i < text.Length; i++)         {             if (char.IsUpper(text[i]))                 newText.Append(' ');             newText.Append(text[i]);         }         return newText.ToString();     }

Encryption and Decryption in c#

Encryption and Decryption in c# 1)Create new class named as Serialization inside it create two new function copied following code to that class. 2)Passes  value in the query string and call the method Encryptnew to Encript the value.     Ex:-          Response.Redirect("Querytest.aspx?val="+ClassName.Seralize.EncryptNew(txtname.Text)); 3)Decrypte the value which is getting from query string....     Ex:-         Label lblresult = new Label();             lblresult.Text = BAL_Yahoo.Seralize.DecryptNew(Request.QueryString["val"].ToString());             form1.Controls.Add(lblresult); This code is very very important for Encrypte and decrypte values in the C#......... Used in online banking site and social network site to security perpouse. public static string EncryptNew(string pstrText)         {             string pstrEncrKey = "1239;[pewGKG)NisarFidesTech";             byte[] byKey = { };             byte[] IV = { 18, 52, 86, 120,

Java script for accept only numbers

  function fnCheckIntegerValue(e, o) {             var vTxtVal = o.value;             var sTst = false;             evt = e || window.event;             var keyPressed = evt.which || evt.keyCode;             if (keyPressed < 58 && keyPressed > 47) {                 sTst = true;             }             else {                 //o.value = vTxtVal;                 //e.returnValue = false;                 sTst = false;             }             return sTst;         }     Event in submit button onkeypress="return fnCheckIntegerValue(event, this);"