文件上传/下载/删除
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实现文件的上传下载和删除