页面上有个按钮A,点击A生成一个压缩包并要将这个压缩包下载下来。
生成压缩包的功能已实现,现在要实现同时下载的功能,我的初步想法是在
页面上放一个超链接,生成压缩包的同时生成超链接,但是大家都知道超链接
是需要点击才能实现下载的,我要实现的就是不用点击超链接,在点按钮A生成压缩包的
同时将生成的压缩包下载下来?
生成压缩包的功能已实现,现在要实现同时下载的功能,我的初步想法是在
页面上放一个超链接,生成压缩包的同时生成超链接,但是大家都知道超链接
是需要点击才能实现下载的,我要实现的就是不用点击超链接,在点按钮A生成压缩包的
同时将生成的压缩包下载下来?
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AddHeader("Content-Disposition", "attachment;filename="+HttpUtility.UrlEncode(fileName)) ;
Response.WriteFile(fullName,0,length);
Response.Flush();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;FileName="+YourFileName);
Response.BinaryWrite((byte[])YourFileData.Rows[0]["AttachmentContent"]);
Response.End();
/// 文件下载
/// </summary>
/// <param name="FileName">要下载的文件名称</param>
public void DownFile(string FileName)
{
string path = Server.MapPath("~/" + FileName);
string SaveFileName = path.Substring(path.LastIndexOf("\\") + 1);
FileStream myFile = File.OpenRead(path);
byte[] fileCont = new byte[myFile.Length];
myFile.Read(fileCont, 0, (int)myFile.Length);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + SaveFileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", myFile.Length.ToString());
//HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.BinaryWrite(fileCont);
}
我的qq为121067015 [email protected]
我的代码是这样子写的
wName = Zip;
[align=left]WorkName = string.Format("<a href='{0}'>{1}</a>", Zip, Zip.Substring(Zip.LastIndexOf('/') + 1)); Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream"; Response.ContentEncoding = System.Text.Encoding.Default;
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Zip.Substring(Zip.LastIndexOf('/') + 1))); Response.WriteFile(Zip, 0, 52428800);
Response.Flush(); [/align]下载下来打开提示压缩文件格式未知或数据已损坏
long fsize = fs.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition","attachment; filename='" + HttpUtility.UrlEncode("3.zip",System.Text.Encoding.UTF8) + "'");
Response.AddHeader("Content-Length",fsize.ToString()); byte[] fileBuffer = new byte[fsize];
fs.Read(fileBuffer, 0, (int)fsize);
fs.Close();
Response.BinaryWrite(fileBuffer);
Response.End();
Response.Redirect(hrefPath+fileName);