2010-04-28 39 views
0
ZipFileToCreate = "c:\user\desktop\webservice\file.zip"; 

所以,當我嘗試保存此文件時,它會創建\當我嘗試保存此文件時,它會創建和文件夾的整個路徑

像用戶\桌面\ web服務\文件路徑的文件夾爲什麼這樣?

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

'Parameter'有什麼值? – ChrisF 2010-04-28 12:07:41

回答

1

我認爲你需要使用Environment.GetFolderPath方法來查找當前用戶的桌面文件夾,而不是硬編碼爲‘C:\用戶\桌面\ web服務\ file.zip’。還使用Path.Combine來構建路徑比字符串連接更可靠。嘗試

Parameter = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "file.zip"); 
相關問題