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    ...

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();        ...

Add New Columns and Add rows into table from list values in C#

DataTable dtt = new DataTable(); dtt.Columns.Add("Name"); dtt.Columns.Add("ContactID"); dtt.Columns.Add("Date");   foreach (var Item in qu.AsEnumerable())    {      DataRow dr = dtt.NewRow();      dr["Name"] = Item.Name;      dr["ContactID"] = Item.ContactID;      dtt.Rows.Add(dr);    }

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 />      ...

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                  ...

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 ...