C# 在asp.net中插入用于保存zip文件的相对路径
我编写这个函数是为了创建一个zip存档C# 在asp.net中插入用于保存zip文件的相对路径,c#,asp.net,zip,C#,Asp.net,Zip,我编写这个函数是为了创建一个zip存档 protected void ImageButton_documenti_Click(object sender, ImageClickEventArgs e) { string path_cartella = @"d:\work\project1\temp\document"; string path_cartella_zip = @"d:\work\project1\temp\document_zip\
protected void ImageButton_documenti_Click(object sender, ImageClickEventArgs e)
{
string path_cartella = @"d:\work\project1\temp\document";
string path_cartella_zip = @"d:\work\project1\temp\document_zip\";
path_cartella_zip = path_cartella_zip + "zip_documenti_al_" + System.DateTime.Now.ToString("ddMMyyyy") + ".zip";
//al click dell'immagine creo un file zip contenente tutte le cartelle dei documenti
using (ZipFile zip = new ZipFile())
{
try
{
zip.AddDirectory(path_cartella);
zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
zip.Save(path_cartella_zip);
operazione_ok.Visible = true;
operazione_ok.InnerText = "Procedura di zip attivata.";
}
catch (Exception errore)
{
elenco_errori.Visible = true;
elenco_errori.InnerText = errore.Message;
}
}
}
此函数在本地运行正常,但在我的web服务器上,我不知道绝对路径,我想更改“string\u path\u cartella”和“string\u path\u cartella\u zip”,以便在“temp/document”文件夹中使用相对路径保存文档
string path_cartella = Server.MapPath("~/temp/document");
string path_cartella_zip = Server.MapPath("~/temp/document_zip");
参考: