在程序里面(服务器端)调用Winrar压缩文件的方法?另寻求一条语句转换的方法。vb.net到C#。
1
case("zip"): // 压缩
2
string[] zip_tmp = this.name1.Value.Split(new char[]{'*'});
3
string zip_tmp1= zip_tmp[zip_tmp.Length-1];
4
if(this.CheckName(zip_tmp1)) //检测文件命名的合法性
5
{
6
string zip_tmp2=zip_tmp1.Replace(".zip","");
7
8
//移除“.zip”后缀,并防止名称重复
9
10
this.NameExisted(1,ServerDir+@"personal\"+zip_tmp2+".zip",out zip_tmp2);
11
StreamWriter zip_sr =File.CreateText(ServerDir+"list.dat");
12
zip_sr.Write("");
13
zip_sr.Close();
14
for(int m =0;m<zip_tmp.Length-1;m++)
15
{
16
//以系统默认的 ANSI 编码创建压缩文件列表
17
18
StreamWriter zip_sw2 =new StreamWriter(ServerDir+"list.dat",true,System.Text.Encoding.Default);
19
zip_sw2.WriteLine(ServerDir+zip_tmp[m]);
20
zip_sw2.Close();
21
}
22
System.Diagnostics.Process Process1=new System.Diagnostics.Process();
23
Process1.StartInfo.FileName=ServerDir+"Winrar.exe";
24
Process1.StartInfo.Arguments=" a -ep1 -inul -y "+zip_tmp2+@" @"+ServerDir+"list.dat";
25
Process1.Start(); //进行压缩
26
while(!Process1.HasExited) //等待压缩的完成
27
{
28
}
29
}
30
break;
31
case("unzip"): //解压缩
32
string [] un_tmp =this.name1.Value.Split(new char[]{'*'});
33
int i2=0; //防止名称冲突的参数
34
foreach(string un_tmp2 in un_tmp)
35
{
36
if(un_tmp2!="")
37
{
38
string un_time=System.DateTime.Now.ToShortDateString()+"-"+System.DateTime.Now.Hour.ToString()+"-"+System.DateTime.Now.Minute.ToString()+"-"+(System.DateTime.Now.Second+i2).ToString();
39
string un_dir =ServerDir+@"personal\Unzip-"+un_time;
40
Directory.CreateDirectory(un_dir); //创建以解压时间为名的文件夹
41
StreamWriter un_sw=File.AppendText(ServerDir+"DirState.dat");
42
un_sw.Write(@"personal\Unzip-"+un_time+"*");
43
un_sw.Close();
44
System.Diagnostics.Process Process2=new System.Diagnostics.Process();
45
Process2.StartInfo.FileName=ServerDir+"Winrar.exe";
46
Process2.StartInfo.Arguments=" x -inul -y "+ServerDir+un_tmp2+" "+un_dir;
47
Process2.Start(); //进行解压
48
while(!Process2.HasExited) //等待解压的完成
49
{
50
}
51
i2++;
52
}
53
}
54
break;
55
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
case("zip"): // 压缩2
string[] zip_tmp = this.name1.Value.Split(new char[]{'*'});3
string zip_tmp1= zip_tmp[zip_tmp.Length-1];4
if(this.CheckName(zip_tmp1)) //检测文件命名的合法性5
{6
string zip_tmp2=zip_tmp1.Replace(".zip","");7

8
//移除“.zip”后缀,并防止名称重复9

10
this.NameExisted(1,ServerDir+@"personal\"+zip_tmp2+".zip",out zip_tmp2);11
StreamWriter zip_sr =File.CreateText(ServerDir+"list.dat");12
zip_sr.Write("");13
zip_sr.Close();14
for(int m =0;m<zip_tmp.Length-1;m++)15
{16
//以系统默认的 ANSI 编码创建压缩文件列表17

18
StreamWriter zip_sw2 =new StreamWriter(ServerDir+"list.dat",true,System.Text.Encoding.Default); 19
zip_sw2.WriteLine(ServerDir+zip_tmp[m]);20
zip_sw2.Close();21
}22
System.Diagnostics.Process Process1=new System.Diagnostics.Process();23
Process1.StartInfo.FileName=ServerDir+"Winrar.exe";24
Process1.StartInfo.Arguments=" a -ep1 -inul -y "+zip_tmp2+@" @"+ServerDir+"list.dat";25
Process1.Start(); //进行压缩26
while(!Process1.HasExited) //等待压缩的完成27
{28
}29
}30
break;31
case("unzip"): //解压缩32
string [] un_tmp =this.name1.Value.Split(new char[]{'*'});33
int i2=0; //防止名称冲突的参数34
foreach(string un_tmp2 in un_tmp)35
{36
if(un_tmp2!="")37
{38
string un_time=System.DateTime.Now.ToShortDateString()+"-"+System.DateTime.Now.Hour.ToString()+"-"+System.DateTime.Now.Minute.ToString()+"-"+(System.DateTime.Now.Second+i2).ToString();39
string un_dir =ServerDir+@"personal\Unzip-"+un_time;40
Directory.CreateDirectory(un_dir); //创建以解压时间为名的文件夹41
StreamWriter un_sw=File.AppendText(ServerDir+"DirState.dat");42
un_sw.Write(@"personal\Unzip-"+un_time+"*");43
un_sw.Close();44
System.Diagnostics.Process Process2=new System.Diagnostics.Process();45
Process2.StartInfo.FileName=ServerDir+"Winrar.exe";46
Process2.StartInfo.Arguments=" x -inul -y "+ServerDir+un_tmp2+" "+un_dir;47
Process2.Start(); //进行解压48
while(!Process2.HasExited) //等待解压的完成49
{50
}51
i2++;52
}53
}54
break;55




浙公网安备 33010602011771号