刚做了一个压缩文件的程序,在本机上测试可以压缩,但压缩服务器上的共享文件时说我没有权限读取文件和创建压缩包,网上搜了哈,说的最多的 net use 但不知道咋用 呵呵 求解决 private void button1_Click(object sender, EventArgs e)
{
//要压缩的文件路径
string zipaaa =@"E:\测试\cslsx\120714-8E-cover";
//压缩后的文件路径
string upzip = @"E:\测试\压缩";
button1.Enabled = false;
string appDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase.Replace("/", "\\");
string rarpath = appDir + "Rar.exe"; //Rar.exe 路径 string rarfile = upzip + "\\ " + zipaaa.Substring(zipaaa.LastIndexOf('\\') + 1) + ".rar"; //压缩包名称
System.IO.DirectoryInfo[] di = new System.IO.DirectoryInfo(zipaaa).GetDirectories();
Process proc = new Process();
foreach (System.IO.DirectoryInfo item in di)
{
ProcessStartInfo pinfo = new ProcessStartInfo
{
FileName = rarpath,
Arguments = " a -r -rr10% -ilog" + appDir + "\\err.log -inul -y \"" + rarfile + "\" \"" + item.FullName + "\\\" -ep1 -ap" + item,
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = appDir,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput=true,
RedirectStandardOutput=true
};
proc = new Process { StartInfo = pinfo };
proc.Start();
proc.WaitForExit(1000);
}
if (proc.ExitCode == 0)
{
proc.Close();
MessageBox.Show("压缩成功 \n");
button1.Enabled = true;
}
else
{
proc.Close();
MessageBox.Show(" 压缩失败 \n");
button1.Enabled = true;
}
}
{
//要压缩的文件路径
string zipaaa =@"E:\测试\cslsx\120714-8E-cover";
//压缩后的文件路径
string upzip = @"E:\测试\压缩";
button1.Enabled = false;
string appDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase.Replace("/", "\\");
string rarpath = appDir + "Rar.exe"; //Rar.exe 路径 string rarfile = upzip + "\\ " + zipaaa.Substring(zipaaa.LastIndexOf('\\') + 1) + ".rar"; //压缩包名称
System.IO.DirectoryInfo[] di = new System.IO.DirectoryInfo(zipaaa).GetDirectories();
Process proc = new Process();
foreach (System.IO.DirectoryInfo item in di)
{
ProcessStartInfo pinfo = new ProcessStartInfo
{
FileName = rarpath,
Arguments = " a -r -rr10% -ilog" + appDir + "\\err.log -inul -y \"" + rarfile + "\" \"" + item.FullName + "\\\" -ep1 -ap" + item,
WindowStyle = ProcessWindowStyle.Hidden,
WorkingDirectory = appDir,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput=true,
RedirectStandardOutput=true
};
proc = new Process { StartInfo = pinfo };
proc.Start();
proc.WaitForExit(1000);
}
if (proc.ExitCode == 0)
{
proc.Close();
MessageBox.Show("压缩成功 \n");
button1.Enabled = true;
}
else
{
proc.Close();
MessageBox.Show(" 压缩失败 \n");
button1.Enabled = true;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货