当前位置:编程学习 > C#/ASP.NET >>

Process文件名应该怎么写?急!!

代码如下:
 Process p = new Process();
            p.StartInfo.UseShellExecute = true;
            p.StartInfo.FileName = "WinRAR";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.Arguments = " e -O+ " + fileName ;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            p.Start();
            if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
            }
在源码中运行是正确的,可生成EXE后就会提示没有找到WinRAR文件,请各位高手指教!!! --------------------编程问答-------------------- 写全名
WinRAR.exe  --------------------编程问答-------------------- http://tech.it168.com/d/2008-04-09/200804091354149.shtml --------------------编程问答-------------------- p.StartInfo.FileName = "WinRAR"; 

应该是winrar.exe的全路径吧,否则应该是找不到的。 --------------------编程问答-------------------- 写全名时在运行到p.Start(); 时就会提示

调用的目标发生了异常。 --------------------编程问答-------------------- 应该没问题的,还有就是fileName要写对,全路径。或者是你的winrar版本有问题。。。 --------------------编程问答-------------------- 写全路径也是同样的问题 --------------------编程问答--------------------
引用 1 楼 lcl_data 的回复:
写全名
WinRAR.exe

1.
p.StartInfo.FileName = "WinRAR.exe"; 程序的当前目录下的WinRAR.exe
不然你要写绝对路径

2.
 if (System.IO.File.Exists(fileName)) 
            { 
                System.IO.File.Delete(fileName); 
            } 

建议读winrar的输出数据判断退出,再检查是否压缩完成 --------------------编程问答-------------------- 设置下WorkingDirectory属性
 p.StartInfo.WorkingDirectory="Winrar所在文件夹的地址";
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,