知道StartInfo.Arguments(进程命令行参数)用法的人请进!
zklvy 2004-04-08 09:20:41 我在做文件上传时候需要先压缩上传,再解压缩到临时目录下。
压缩上传还好解决,但解压缩时,我用的进程的执行程序是rar的解压缩执行程序:unrar.exe
这是需要设置StartInfo.Arguments 参数的,一个朋友告诉我这样用:
unrar.StartInfo.Arguments = " x -o+ " + rar + " " + temp.Value;
我的程序如下:
//选择上传
private void Submit1_ServerClick(object sender, System.EventArgs e)
{
if(data2.PostedFile.FileName.ToLower().Substring(data2.PostedFile.FileName.LastIndexOf(".")) != ".gsp")
{
hint.Text = "1、非法文件格式,请重新选择上传!";
}
else if(data2.PostedFile.ContentLength == 0)
{
hint.Text = "1、零字节文件,请重新选择上传!";
}
else
{
string path = MapPath("../data/");
temp.Value = path + DateTime.Now.ToString("MMddHHmmssfff");
string rar = temp.Value + @"\info.rar";
//创建临时目录
Directory.CreateDirectory(temp.Value);
//上传文件
data2.PostedFile.SaveAs(rar);
//解包到临时目录
Process unrar = new Process();
unrar.StartInfo.FileName = MapPath("../data/unrar.exe");
unrar.StartInfo.Arguments = " x -o+ " + rar + " " + temp.Value;
unrar.StartInfo.UseShellExecute = false;
unrar.Start();
unrar.WaitForExit();
unrar.Dispose();
//删除原包文件
if(File.Exists(rar))
{
File.Delete(rar);
}
}
//这样是可以的,我不明白为什么这样设置StartInfo.Arguments的参数!!!