Skip to main content

Posts

Showing posts from September, 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.