文件上传/下载/删除

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件上传/下载/删除相关的知识,希望对你有一定的参考价值。

【文件上传】
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 = "文件上传成功";
this.lbShowFile.Text = Filename;
}
else
{
this.lbUpLoad.Text = "";
}
}
catch (Exception ex)
{
this.lbUpLoad.Text = "上传发生错误! 信息:" + ex.ToString();
}
}


【文件下载】
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 = "文件上传成功";
this.lbShowFile.Text = Filename;
}
else
{
this.lbUpLoad.Text = "";
}
}
catch (Exception ex)
{
this.lbUpLoad.Text = "上传发生错误! 信息:" + ex.ToString();
}
}

【文件删除】
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);
}

}

以上是关于文件上传/下载/删除的主要内容,如果未能解决你的问题,请参考以下文章

文件上传/下载/删除

Linux FTP服务器怎么设置 可以上传可以下载但是不能删除的权限?

文件上传下载删除

SpringBoot整合FastDFS实现文件的上传下载和删除

SpringBoot整合FastDFS实现文件的上传下载和删除

C#实现多文件上传,写到文件夹中,获取文件信息以及下载文件和删除文件