protected void ButUp_Click(object sender, EventArgs e)
{
if (this.FileUpload1.PostedFile.ContentLength > 0)
{
string fullname = this.FileUpload1.PostedFile.FileName;
string imagename = System.IO.Path.GetFileName(fullname);
string name = imagename.Replace(".zip", "");
string imagepath = @"~\chuangkou\temporary\photo\"+ name;
string wjpath = Server.MapPath(imagepath + ".zip");
this.FileUpload1.SaveAs(wjpath);
OperaRAR aa = new OperaRAR();
aa.unCompressRAR(imagepath+"\\", wjpath, "aaa");//这里面得imagepath+"\\"是要解压到得路径,wjpath是需要解压的文件,只不过这两个都是虚拟路径,为什么找不到虚拟路径下的文件呢?我换成本地的路径就好好的!
Response.Write("上传成功!");
}
else
{
return;
}
}
坐等大虾!
{
if (this.FileUpload1.PostedFile.ContentLength > 0)
{
string fullname = this.FileUpload1.PostedFile.FileName;
string imagename = System.IO.Path.GetFileName(fullname);
string name = imagename.Replace(".zip", "");
string imagepath = @"~\chuangkou\temporary\photo\"+ name;
string wjpath = Server.MapPath(imagepath + ".zip");
this.FileUpload1.SaveAs(wjpath);
OperaRAR aa = new OperaRAR();
aa.unCompressRAR(imagepath+"\\", wjpath, "aaa");//这里面得imagepath+"\\"是要解压到得路径,wjpath是需要解压的文件,只不过这两个都是虚拟路径,为什么找不到虚拟路径下的文件呢?我换成本地的路径就好好的!
Response.Write("上传成功!");
}
else
{
return;
}
}
坐等大虾!
{
/// <summary>
/// 是否安装了Winrar
/// </summary>
/// <returns></returns>
static public bool Exists()
{
RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString());
}
/// <summary>
/// 解压
/// </summary>
/// <param name="unRarPatch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
/// <returns></returns>
public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info; try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
//the_rar = the_rar.Substring(1, the_rar.Length - 7); if (Directory.Exists(unRarPatch) == false)
{
Directory.CreateDirectory(unRarPatch);
}
the_Info = "x " + rarName + " " + unRarPatch + " -y"; ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径 Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return unRarPatch;
}
}这是解压的代码
不过用虚拟路径行么?
你必须将虚拟路径对应到物理路径才能执行相关文件操作工作。
用Server.MapPath()取得主路径。