我正在尝试下载一个zip文件,并以相同的方式提取并运行未压缩的内容,但是当执行代码时,zip文件正在服务器位置提取,并且内容也在该位置运行。下面是我编写的代码。我已经在本地网络上托管了代码。我什至尝试了Write()而不是TransmitFile()
try
{
string launchPresentationPath = Convert.ToString(e.CommandArgument);
string exeFolder = launchPresentationPath.Replace("/Launch_Presentation.exe", "");
string path = HttpContext.Current.Request.PhysicalApplicationPath + "/Uploads/" + exeFolder + ".zip"; //+ Convert.ToString(e.CommandArgument);
string userRoot = System.Environment.GetEnvironmentVariable("USERPROFILE");
string str1 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
downloadFolder = Path.Combine(userRoot, "Downloads");
string strAttach = "attachment; filename=" + exeFolder.Substring(exeFolder.IndexOf('/') + 1) + ".zip";
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
HttpResponse res = HttpContext.Current.Response;
res.Clear();
res.AppendHeader("content-disposition", strAttach);
res.ContentType = "application/octet-stream";
res.TransmitFile(path);
using (ZipFile zip2 = ZipFile.Read(path))
{
zip2.ExtractAll(downloadFolder, Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
}
DirectoryInfo f = new DirectoryInfo(downloadFolder + "\\" + exeFolder.Substring(exeFolder.IndexOf('/') + 1));
FileInfo[] a = f.GetFiles();
if (a.Length > 0)
{
ProcessStartInfo myProcess = new ProcessStartInfo(downloadFolder + "\\" + exeFolder.Substring(exeFolder.IndexOf('/') + 1) + "\\Launch_Presentation.exe");
myProcess.UseShellExecute = false;
Process process = Process.Start(myProcess);
int Exeid = process.Id;
this.Visible = false;
this.Visible = true;
process.EnableRaisingEvents = true;
pdfFrame.Visible = videoFrame.Visible = false;
Response.Redirect(Convert.ToString(this.Page.Request.Url.AbsoluteUri));
process.Exited += (myProcess_HasExited);
}
res.Flush();
res.End();
}
}
catch (Exception ex)
{
}
为什么它不在客户端位置下载?
答案 0 :(得分:0)
可能是与定义为downloadFolder的客户端路径的许可有关的问题。请检查并通知我。