// Read File Information
String filecate = system. configuration. configurationmanager. receivettings ["filecatelog"];
String fielpath = server. mappath ("") + "\" + filecate + "\\";
String [] fname = directory. getfiles (fielpath );
For (INT I = 0; I <fname. length; I ++)
{
String fn = "";
Long Len = 0;
String creatdate = "";
Fileinfo fi1 = new fileinfo (fname [I]. tostring ());
If (fi1.exists)
{
Creatdate = fi1.creationtime. tostring ("mm DD, YYYY ");
Len = fi1.length;
Filetype = fi1.extension. tostring ();
}
Fn = fname [I]. substring (fname [I]. lastindexof ("\") + 1, fname [I]. length-fname [I]. lastindexof ("\")-1 );
}
// Save the uploaded file
Private void uploadsaveas ()
{
Int filecount = request. Files. count;
If (filecount> 0)
{
String [] afilename;
String uploadpath;
Uploadpath = system. configuration. configurationmanager. receivettings ["filecatelog"] + "\\";
Char [] De = {'\\'};
Httppostedfile HPF = request. Files [0];
Afilename = HPF. filename. Split (de );
String uploadfilename = afilename [afilename. Length-1];
If (uploadfilename! = "" & HPF. contentlength> 0)
{
If (HPF. contentlength> 20000*1024)
{
Response. Write ("<script language = 'javascript '> alert ('file is too large to upload! '); </SCRIPT> ");
Return;
}
String filecate = system. configuration. configurationmanager. receivettings ["filecatelog"];
String fielpath = server. mappath ("") + "\" + filecate + "\\";
String [] fname = directory. getfiles (fielpath );
For (INT I = 0; I <fname. length; I ++)
{
Fileinfo fi1 = new fileinfo (fname [I]. tostring ());
If (fi1.name = uploadfilename)
{
Response. write ("<script language = 'javascript '> alert ('this file already exists on the server. Please select another file or change the file name and upload it again'); </SCRIPT> ");
// Response. Write ("<SCRIPT> alert ('the file with the same name already exists on the server. Please select another file or change the file name and upload it again ') </SCRIPT> ");
Return;
}
}
String strfilepath = This. Request. filepath;
String strpath = path. getdirectoryname (strfilepath );
String destfilename = uploadpath + uploadfilename;
Try
{
HPF. saveas (server. mappath (destfilename ));
This. lbmsg. Text = "the file is uploaded successfully! ";
}
Catch (exception ex)
{
This. lbmsg. Text = ex. tostring ();
}
}
Else if (HPF. contentlength> = 0)
{
Response. Write ("<script language = 'javascript '> alert (' the file content is empty. Please select another file! '); </SCRIPT> ");
Return;
}
}
}
// Download an object
1. Bind the connection to the file name
(Hyperlink) This. gridview1.rows [I]. cells [3]. findcontrol ("hyperlink1 ")). navigateurl = filecate + "/" + this. gridview1.rows [I]. cells [0]. text;
2. Directly write in table
TC. TEXT = "<a Title = \" click to download \ "href = \" "+ file directory +" \ "+ file name +" \ ">" + file name + "</ a> ";