在.net中如何写文件上传下载代码

bjsummer123 2010-12-08 05:24:08
想要在页面中实现文件上传下载功能,哪位大师可以帮帮忙啊
...全文
77 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-12-08
  • 打赏
  • 举报
回复
web fileupload
FileInfo Fi = new FileInfo(filePath);
if (Fi.Exists)
{
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=1.excel");
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
string path = Server.MapPath("~/") + "";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(obj.Name, System.Text.Encoding.GetEncoding("utf-8")));
Response.ContentType = "application/octet-stream";
Response.WriteFile("" + path + "");
Response.End();


if (fileUpload.HasFile)
{
string savePath = Server.MapPath("~/upload/");
if(!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
savePath = savePath + "\\" + fileUpload.FileName;
fileUpload.SaveAs(savePath);
}
bjsummer123 2010-12-08
  • 打赏
  • 举报
回复
具体的代码怎么写啊,初学者 不太懂也
d563382384 2010-12-08
  • 打赏
  • 举报
回复
FileUpload 实现文件上传 .save方法保存上传的文件
keketian521 2010-12-08
  • 打赏
  • 举报
回复
帮顶下!!!!!!!!!!

13,347

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET技术前瞻
社区管理员
  • .NET技术前瞻社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧