asp.net 实现文件上传和下载
asp.net 实现文件上传和下载
来源:中国IT实验室 作者:佚名 发表于:2013-01-30 10:43 点击:
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-s
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);
}
有帮助
(0)
0%
没帮助
(0)
0%
上一篇:asp.net两种方式短信接口使用
下一篇:ASP.NET将文件写到另一服务器