插入相对路径以在asp.net中保存zip文件

时间:2014-01-14 09:55:24

标签: 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\";
        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;
            }   
        }
    }

这个功能在本地工作正常,但在我的网络服务器上,我不知道绝对路径,我想改变" string_path_cartella"和" string_path_cartella_zip"用于在" temp / document"中保存具有相对路径的文档夹

1 个答案:

答案 0 :(得分:2)

试试这个:

string path_cartella = Server.MapPath("~/temp/document");
string path_cartella_zip = Server.MapPath("~/temp/document_zip");

参考:http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath%28v=vs.110%29.aspx