string fileRar = DateTime.Now.ToString("yyyyMMddhhmmss");
string file = Server.MapPath("~/rar/") +fileRar+ "3.rar";
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications/WinRAR.exe/shell/open/command"); //win 2003 xp 查找rar的注册表
if (the_Reg == null)
{
the_Reg = Registry.ClassesRoot.OpenSubKey("WinRAR\\Shell\\Open\\Command"); //server 2008/win7
}
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + fileRar + " " +pathFile; //执行命令 压缩后的文件 被压缩的文件
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = Server.MapPath("~/rar/");//获取或设置要启动的进程的初始目录。初始化目录
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start(); //执行成功
the_Process.Close();
the_Process.Dispose();/*执行到这里 已经生成把我的txt压缩成rar*/ 并且可以使用 关键是输出流让用户下载 下载可以正常下载 只是下载后的
不能解压 而我打开根目录下面的生成 rar是可以解压并正常使用的。 下载后的报(此档案格式末知或已损坏)Response.ContentType = "WinRar/rar";
Response.AppendHeader("Content-Disposition", "attachment;filename=aaaa.rar");//用法的方式输出
Response.BinaryWrite(File.ReadAllBytes(file)); //弹出下载框/*就是这个流输出的问题 可又找不到是哪里的问题 输出txt是正常的 excel也是正常的*/
string file = Server.MapPath("~/rar/") +fileRar+ "3.rar";
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications/WinRAR.exe/shell/open/command"); //win 2003 xp 查找rar的注册表
if (the_Reg == null)
{
the_Reg = Registry.ClassesRoot.OpenSubKey("WinRAR\\Shell\\Open\\Command"); //server 2008/win7
}
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + fileRar + " " +pathFile; //执行命令 压缩后的文件 被压缩的文件
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = Server.MapPath("~/rar/");//获取或设置要启动的进程的初始目录。初始化目录
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start(); //执行成功
the_Process.Close();
the_Process.Dispose();/*执行到这里 已经生成把我的txt压缩成rar*/ 并且可以使用 关键是输出流让用户下载 下载可以正常下载 只是下载后的
不能解压 而我打开根目录下面的生成 rar是可以解压并正常使用的。 下载后的报(此档案格式末知或已损坏)Response.ContentType = "WinRar/rar";
Response.AppendHeader("Content-Disposition", "attachment;filename=aaaa.rar");//用法的方式输出
Response.BinaryWrite(File.ReadAllBytes(file)); //弹出下载框/*就是这个流输出的问题 可又找不到是哪里的问题 输出txt是正常的 excel也是正常的*/
解决方案 »
- 关于把评论框隐藏之后里面的button的click事件
- asp.net中如何用CSS控制DataGrid网格线的颜色
- repeater 嵌套 protected void repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) 无法将类型为“System.Data.Common.DbDataRecor
- @aa必须声明标量变量 "@aa"
- 请大家帮忙解释一下!!!
- 使用excel权限的问题!
- 怎样用一个事件处理函数处理一个页面的多个button?
- 请教大侠
- 有谁用过powerup treeview ???我下了一个不会用呀?好象系统不认!!!
- DataList的AlternatingItemStyle问题!
- CKfinder问题!有用过的进来聊聊!
- ASP.NET单点登录到jsp的系统
用Response.ContentType = "application/octet-stream";试试?
int readCount = FtpStream.Read(buffer, 0, buffer.Length);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
while (readCount > 0)
{
Response.OutputStream.Write(buffer, 0, readCount);
readCount = FtpStream.Read(buffer, 0, buffer.Length);
}
猜测下载的文件要大那么一点,要么没先Response.Clear();
要么输出了额外的东西
不知道你程序流程,是压缩了就下载吗
还没压完,文件是独占式访问
File.ReadAllBytes报错
因为已设置了ResponseHeader
所以错误页已rar文件形式被下载
要等压缩完成,需要正确使用
the_Process.WaitForExit(n);
好像