我用了你下面得程序进行压缩文件夹,程序执行完了,也没有报错,但是在硬盘上没有看到rar文件,是怎么回事?还需要其他得吗?
/// <summary>
/// 调用DOS命令,注意多条DOS命令必须以|号隔开
/// </summary>
/// <param name="argm">要操作的DOS命令</param>
/// <returns>返回取到的信息值</returns>
static public string mycmd(string argm)
{
string myOutString = "";
//开始创建文件
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe"; try
{
p.Start();
string[] ary = argm.Split('|');
for(int i=0;i<ary.Length;i++)
{
p.StandardInput.WriteLine(ary[i].ToString());
}
p.StandardInput.WriteLine("exit");
myOutString = p.StandardOutput.ReadToEnd();
p.Close();
}
catch(Exception ex)
{
throw new Exception (ex.Message);
} return(myOutString);
}
调用命令:
mycmd("rar a d:\\sql\\xxx.rar d:\\sql\\xxx.gif");
/// <summary>
/// 调用DOS命令,注意多条DOS命令必须以|号隔开
/// </summary>
/// <param name="argm">要操作的DOS命令</param>
/// <returns>返回取到的信息值</returns>
static public string mycmd(string argm)
{
string myOutString = "";
//开始创建文件
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe"; try
{
p.Start();
string[] ary = argm.Split('|');
for(int i=0;i<ary.Length;i++)
{
p.StandardInput.WriteLine(ary[i].ToString());
}
p.StandardInput.WriteLine("exit");
myOutString = p.StandardOutput.ReadToEnd();
p.Close();
}
catch(Exception ex)
{
throw new Exception (ex.Message);
} return(myOutString);
}
调用命令:
mycmd("rar a d:\\sql\\xxx.rar d:\\sql\\xxx.gif");
我单步调试出来得返回
"Microsoft Windows [版本 5.2.3790]\r\n(C) 版权所有 1985-2003 Microsoft Corp.\r\n\r\nc:\\windows\\system32\\inetsrv>rar a c:\\inetpub\\wwwroot\\On Scm AIO\\OnWms\\进库单22(2005-7-20_115034).rar c:\\inetpub\\wwwroot\\On Scm AIO\\OnWms\\进库单22(2005-7-20_115034)\r\n\r\nc:\\windows\\system32\\inetsrv>exit\r\n"
hoho~~~~~~~
2.你的服务器上必须有安装rar压缩软件.
3.你的目录,除了设置everyone可读取写入,还必须设置aspnet用户可修改权限
4.如果还不行,你可把你上述DOS命令直接在DOS下执行看看会出现什么问题.
由于aspnet用户的权限可能会有所限制,建议你将rar.exe文件直接放在你网站的目录下进行调用,不要跑到windows目录下去调用.
http://www.microsoft.com/china/msdn/library/langtool/vcsharp/miszipcompression.mspx