asp.net怎么读取上传文件夹的内容显示出来并且可以删除功能(后台上传文件管理)
展开全部
可以读取文件夹的名称 点击进行下载
string FileName = “名称”;
string path = Server.MapPath("路径") + "\\" + FileName;
Response.BufferOutput = false;
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(FileName));
Response.ContentType = "application/octstream";
Response.CacheControl = "Private";
Stream stm = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
Response.AppendHeader("Content-length", stm.Length.ToString());
BinaryReader br = new BinaryReader(stm);
byte[] bytes;
for (Int64 x = 0; x < (br.BaseStream.Length / 4096 + 1); x++)
{
bytes = br.ReadBytes(4096);
Response.BinaryWrite(bytes);
System.Threading.Thread.Sleep(5); //休息一下,防止耗用带宽太多。
}
stm.Close();
如果删除的话分两种 从数据库中删除和从文件夹中删除
数据库中删除则删除数据
从文件夹中删除数据
//删除文件夹中的文件
string delete = Server.MapPath("路径") +文件名称;
System.IO.File.Delete(delete);
string FileName = “名称”;
string path = Server.MapPath("路径") + "\\" + FileName;
Response.BufferOutput = false;
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(FileName));
Response.ContentType = "application/octstream";
Response.CacheControl = "Private";
Stream stm = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
Response.AppendHeader("Content-length", stm.Length.ToString());
BinaryReader br = new BinaryReader(stm);
byte[] bytes;
for (Int64 x = 0; x < (br.BaseStream.Length / 4096 + 1); x++)
{
bytes = br.ReadBytes(4096);
Response.BinaryWrite(bytes);
System.Threading.Thread.Sleep(5); //休息一下,防止耗用带宽太多。
}
stm.Close();
如果删除的话分两种 从数据库中删除和从文件夹中删除
数据库中删除则删除数据
从文件夹中删除数据
//删除文件夹中的文件
string delete = Server.MapPath("路径") +文件名称;
System.IO.File.Delete(delete);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询