110,561
社区成员
发帖
与我相关
我的任务
分享
if (System.IO.File.Exists(filePath))
{
FileInfo file = new FileInfo(filePath);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //解决中文乱码
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); //解决中文文件名乱码
Response.AddHeader("Content-length", file.Length.ToString());
Response.ContentType = "appliction/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
RegisterClientScriptBlock("", "<script>alert('下载成功')</script>");
}
else
{
RegisterClientScriptBlock("", "<script>alert('文件不存在')</script>");
}
string path = Server.MapPath("~/Upload/" + file.FilePath);
if (System.IO.File.Exists(path))
{
System.IO.FileStream fs = null;
try
{
fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
byte[] buffer = new byte[(int)fs.Length];
fs.Read(buffer, 0, buffer.Length);
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode
(file.FilePath, System.Text.Encoding.UTF8));
Response.BinaryWrite(buffer);
Response.Flush();
Response.End();
}
finally
{
if (fs != null)
{
fs.Close();
}
}
}
if (File.Exists(Server.MapPath("~/Upload/" + FileUpload1.FileName)))
{
MessageBox.Show(this, "该文件已经存在");
}
else
{
try
{
DayLogInfo log = new DayLogInfo();
if (FileUpload1.HasFile)
{
log.FilePath = FileUpload1.FileName;
HttpPostedFile pf = FileUpload1.PostedFile;
pf.SaveAs(Server.MapPath("~/Upload/" + FileUpload1.FileName));
}
}
}
}
if (!this.Page.IsPostBack)
{
string guid = Request.QueryString["GuID"];
try
{
if (Request.Files.Count > 1)
{
int gid = Request.Files.Count - 1;
if (Request.Files[0].ContentLength < 1843200000)
{
string Dir = System.Configuration.ConfigurationManager.AppSettings["TemporyUpload"];
string path = Path.Combine(Dir, guid);
string fileName = System.IO.Path.GetFileName(Request.Files[gid - 1].FileName);
//if (System.IO.Path.GetFileName(Request.Files[1].FileName) != "")
//{
// fileName = System.IO.Path.GetFileName(Request.Files[1].FileName);
//}
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Request.Files[0].SaveAs(Path.Combine(path, fileName));
//Byte a = Request.TotalBytes();
if (File.Exists(Path.Combine(path, fileName)))
{
// int gid = Request.Files.Count - 1;
string js = @"<Script language='JavaScript'>parent.window.showSuccessText(" + gid + "); parent.window.deletePrgs(" + gid + "); </Script>";
// this.Page.ClientScript.RegisterStartupScript(this.GetType(), "uploadstate", "window.top.window.stopUpload(1);", true);//如果和页面建立长连接的话使用,可以实现进度条
this.Page.Response.Write(js);
this.Page.Response.Flush();
fileName = "";
}
else
{
}
}
}
}
catch (Exception ee)
{
string a = ee.Message;
}
System.IO.FileInfo aFile = new System.IO.FileInfo(filePath);
if (aFile.Exists)
{
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.BufferOutput = false;
context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(aFile.Name, System.Text.Encoding.UTF8));
context.Response.AddHeader("Content-Length", aFile.Length.ToString());
context.Response.WriteFile(filePath);
context.Response.Flush();
context.Response.End();
}