ZipFileToCreate = "c:\user\desktop\webservice\file.zip";
因此,当我尝试保存此文件时,它会创建路径的文件夹,如user \ desktop \ webservice \ file \
为什么会这样?
FileStream fs = new FileStream(ZipFileToCreate, FileMode.Open);
byte[] data = new Byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
br.Read(data, 0, data.Length);
br.Close();
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AppendHeader("Content-Disposition", "filename=" + Parameter + ".zip");
DeleteOldFiles();
Response.BinaryWrite(data);
答案 0 :(得分:1)
我认为您需要使用Environment.GetFolderPath
方法查找当前用户的桌面文件夹,而不是硬编码“c:\ user \ desktop \ webservice \ file.zip”。使用Path.Combine
构建路径比字符串连接更可靠。试试
Parameter = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "file.zip");