Sunday, July 27, 2008

Temp table in asp.net

First create the data table and then give the definition for the column
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
DataRow myDataRow;
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.Int32");
myDataColumn.ColumnName = "FileId";
myDataColumn.ReadOnly = true;
myDataColumn.Unique = true;
myDataTable.Columns.Add(myDataColumn);

myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "FileName";
myDataColumn.ReadOnly = false;
myDataTable.Columns.Add(myDataColumn);

Now add the data in that table
myDataRow = myDataTable.NewRow();
myDataRow["FileId"] = i;
myDataRow["FileName"] = NameList[i].ToString();

myDataTable.Rows.Add(myDataRow);
When we delete any row then call the accept change method of the data table

Monday, July 7, 2008

asp.net code to download file in c#

if (e.CommandName == "Download")
{
string strFileName = e.CommandArgument.ToString();
string str = ConfigurationManager.AppSettings["AppPathRead"].ToString() + "/"+ strFileName;
FileInfo fileInfo = new FileInfo(str);
if (fileInfo.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);

}