文件上傳和下載

luoluojin 2006-05-25 04:34:01
怎樣在C#中實現對服務器的文件下載或上傳請高手請教
...全文
126 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yf1025 2006-05-25
  • 打赏
  • 举报
回复
//上传:
用个FileUpload1控键
string sFileName;
sFileName = FileUpload1.FileName;
string sFilePath = Server.MapPath("File");
string strPath = System.IO.Path.Combine(sFilePath, FileUpload1.FileName);
FileUpload1.PostedFile.SaveAs(strPath);
//下载:
string filepath = Server.MapPath("File");
string filename = //下载文件名;
string path = filepath + filename;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
Response.WriteFile(path);
Response.End();

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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