Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ASP.NET中弹出并下载zip文件_C#_Asp.net_File_Zip_Updatepanel - Fatal编程技术网

C# 在ASP.NET中弹出并下载zip文件

C# 在ASP.NET中弹出并下载zip文件,c#,asp.net,file,zip,updatepanel,C#,Asp.net,File,Zip,Updatepanel,我有一个网络表单,其中显示一个带有确认按钮的弹出窗口: <div id="Popup" class="modal hide"> <asp:Panel ID="MyPanel" runat="server"> <asp:UpdatePanel ID="UpdatePanelPopup" runat="server" UpdateMode="Conditional"> <Triggers>

我有一个网络表单,其中显示一个带有确认按钮的弹出窗口:

<div id="Popup" class="modal hide">
    <asp:Panel ID="MyPanel" runat="server">
        <asp:UpdatePanel ID="UpdatePanelPopup" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:PostBackTrigger ControlID="ButtonConfirmerPopup" />
            </Triggers>
            <ContentTemplate>
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">×</button>
                    <h3 id="PopupTitle" runat="server">
                        <asp:Label runat="server" ID="LibelleTitrePopup"></asp:Label></h3>
                </div>
                ....
                <div class="modal-footer">
                    <a href="#" class="btn" data-dismiss="modal">Annuler</a>
                    <asp:Button ID="ButtonConfirmerPopup" ValidationGroup="Submit" runat="server" OnClick="ButtonConfirmerPopup_Click"
                        CssClass="btn btn-success" Text="Confirmer" />
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Panel>
</div>
以及ZIP文件创建(使用ICSharpCode.SharpZipLib.ZIP):

private void GetZipDocumentFormation()
{
如果(ViewState[“DocumentsFormation”]==null)
返回;
var pjs=(列表)ViewState[“DocumentsFormation”];
ViewState[“DocumentsFormation”]=null;
//菲舍尔邮政局
const string fileName=“documents\u formation.zip”;
字符串root=Server.MapPath(“~/Resources/”);
ZipFiles(pjs,string.Format(“{0}\\{1}”,根,文件名));
//HttpResponse response=HttpContext.Current.response;
//response.ClearContent();
//response.Clear();
//response.ContentType=“text/plain”;
//response.AddHeader(“内容处置”、“附件;文件名=“+filename”);
//TransmitFile(string.Format(“{0}\\{1}”,根,文件名));
//response.Flush();
Response.AppendHeader(“内容处置”、“附件;文件名=“+filename”);
Response.ContentType=“应用程序/zip”;
WriteFile(string.Format(“{0}\\{1}”,根,文件名));
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
zip创建是好的,我得到了文件。但弹出窗口始终显示,而UpdatePanel不会更新。 如果我不执行zip文件创建,一切都正常

你能请我帮忙吗

问候

protected void ButtonConfirmerPopup_Click(object sender, EventArgs e)
{
    int idPart = Convert.ToInt32(HiddenFieldIdStagiairePopup.Value);

    if (Convert.ToBoolean(HiddenFieldIsValidationPopup.Value))
    {
        bool result = Valider(idPart);

        if (!result)
            return;

        GetZipDocumentFormation();
        Bootstrap.Message(MessageContainer, "Inscription validée", "alert-success");
        BindListPart();
        UpdatePanelGrid.Update();
        MyPanel.Visible = false;
    }
    else
        Refuser(idPart);
    ButtonConfirmerPopup.Attributes.Remove("data-dismiss");
}
private void GetZipDocumentFormation()
{
    if (ViewState["DocumentsFormation"] == null)
        return;

    var pjs = (List<string>)ViewState["DocumentsFormation"];
    ViewState["DocumentsFormation"] = null;

    // envoi des fichiers en ZIP
    const string fileName = "documents_formation.zip";
    string root = Server.MapPath("~/Resources/");
    Zip.ZipFiles(pjs, string.Format("{0}\\{1}", root, fileName));

    //HttpResponse response = HttpContext.Current.Response;
    //response.ClearContent();
    //response.Clear();
    //response.ContentType = "text/plain";
    //response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
    //response.TransmitFile(string.Format("{0}\\{1}", root, fileName));
    //response.Flush();

    Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
    Response.ContentType = "application/zip";
    Response.WriteFile(string.Format("{0}\\{1}", root, fileName));


    HttpContext.Current.ApplicationInstance.CompleteRequest();
}