0
下面的代碼在創建zip文件時工作正常,但創建的文件有一個文件夾IIS部署>>> WebService ...然後是文本文件,而不僅僅是文本文件。從多個文件創建zip文件
如何將文本文件添加到zip文件?
ZipFile z = ZipFile.Create("C:\\IIS Deploy\\WebServiceTest\\WebServiceTest\\Accident.zip");
//initialize the file so that it can accept updates
z.BeginUpdate();
//add the file to the zip file
z.Add("C:\\IIS Deploy\\WebServiceTest\\WebServiceTest\\test1.txt");
z.Add("C:\\IIS Deploy\\WebServiceTest\\WebServiceTest\\test2.txt");
z.Add("C:\\IIS Deploy\\WebServiceTest\\WebServiceTest\\test3.txt");
//commit the update once we are done
z.CommitUpdate();
//close the file
z.Close();
如果我正確理解你的問題,我認爲解決的辦法可能是創建壓縮文件,並添加內容,而不一個完全合格的路徑。可能還有一個選項可以在Add方法上添加文件(不考慮其包含的路徑)。 –
我試過並得到文件錯誤..應該指定路徑我猜 –
我認爲@codebased答案中提供的解決方案是一個很好的路徑。 –