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也是正常的*/
解决方案 »
- XP home版怎么配置学习环境???
- 散分!顺便谈谈如今的搜索引擎优化!
- 如何在页面中实现自动输入
- 在windows server 2003的系统上怎么Frontpage安装不上,除了用CD盘进行安装以外,还有没有其它的方法可以解决?
- 有一个参数未指定值
- 询问GBK2312编码集
- 用javascript写的不用数据库的省市的二级联动菜单,在asp.net里怎么获取省市的数据啊???
- 我有一个asp.net工程,想转移到别的机器,请问怎么转移,用不用改什么配置文件?
- 请问ASP.NET实现在线的WORD文档编辑要大体怎么做?
- 怎样不让下载????50分
- 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);
好像