"File Upload"
public void Btnfileupload ()
{
try{
if (FileUpLoad.PostedFile.FileName! = "")
{
String path = Server.MapPath ("~/uploads/");
String nowtime = DateTime.Now.ToString ("Yyyymmddhhmmss");
int pos = FileUpLoad.FileName.IndexOf (".");
String Filename =nowtime + fileupload.filename;
String fileall = path + Filename;
String Filename =system.io.path.getextension (fileupload.filename);
Fileupload.saveas (path + Filename);
This.lbUpLoad.Text = "File upload succeeded";
This.lbShowFile.Text = Filename;
}
Else
{
This.lbUpLoad.Text = "";
}
}
catch (Exception ex)
{
This.lbUpLoad.Text = "Upload error occurred! Info: "+ ex." ToString ();
}
}
"File Download"
public void Btnfileupload ()
{
try{
if (FileUpLoad.PostedFile.FileName! = "")
{
String path = Server.MapPath ("~/uploads/");
String nowtime = DateTime.Now.ToString ("Yyyymmddhhmmss");
int pos = FileUpLoad.FileName.IndexOf (".");
String Filename =nowtime + fileupload.filename;
String fileall = path + Filename;
String Filename =system.io.path.getextension (fileupload.filename);
Fileupload.saveas (path + Filename);
This.lbUpLoad.Text = "File upload succeeded";
This.lbShowFile.Text = Filename;
}
Else
{
This.lbUpLoad.Text = "";
}
}
catch (Exception ex)
{
This.lbUpLoad.Text = "Upload error occurred! Info: "+ ex." ToString ();
}
}
"File Delete"
protected void Deleteload_click (object sender, EventArgs e)
{
string fileName = This.lbShowFile.Text;
String strFilePath = Server.MapPath ("~/uploads/" + fileName);
if (file.exists (strFilePath))
{
File.delete (strFilePath);
}
}
File upload/download/delete