上传和下载

天大地大妈咪最大 提交于 2020-02-22 05:20:39

 

//上传:

用个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();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!