Пример #1
0
        protected void grdWQXLog_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "GetFile")
            {
                T_WQX_TRANSACTION_LOG aa = db_Ref.GetWQX_TRANSACTION_LOG_ByLogID(e.CommandArgument.ConvertOrDefault <int>());

                if (aa != null)
                {
                    if (aa.RESPONSE_FILE == null && aa.RESPONSE_TXT == null)
                    {
                        lblMsg.Text = "No validation details because submission succeeded.";
                        return;
                    }

                    byte[] b;
                    if (aa.RESPONSE_FILE != null)
                    {
                        b = aa.RESPONSE_FILE;
                    }
                    else
                    {
                        b = Utils.StrToByteArray(aa.RESPONSE_TXT);
                    }

                    lblMsg.Text = "";

                    Response.Clear();

                    Response.ContentType = "application/x-unknown";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + (aa.RESPONSE_FILE != null ? aa.RESPONSE_TXT : "download.xml") + "\"");
                    Response.Buffer = true;
                    Response.OutputStream.Write(b, 0, b.Length);
//                    Response.BinaryWrite(b);
                    Response.End();
                    Response.Close();
                }
            }
        }
Пример #2
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "GetFile")
            {
                T_WQX_TRANSACTION_LOG aa = db_Ref.GetWQX_TRANSACTION_LOG_ByLogID(e.CommandArgument.ConvertOrDefault <int>());

                if (aa.RESPONSE_FILE != null)
                {
                    lblMsg.Text = "";

                    //attempt to unzip ProcessingReport and just display html report instead of ZIP
                    if (aa.RESPONSE_TXT == "ProcessingReport.zip")
                    {
                        try
                        {
                            if (File.Exists(Server.MapPath("~/tmp/ProcessingReport.xml")))
                            {
                                File.Delete(Server.MapPath("~/tmp/ProcessingReport.xml"));
                            }
                            if (File.Exists(Server.MapPath("~/tmp/result.html")))
                            {
                                File.Delete(Server.MapPath("~/tmp/result.html"));
                            }

                            using (System.IO.Stream stream = new System.IO.MemoryStream(aa.RESPONSE_FILE))
                            {
                                using (var zip = ZipFile.Read(stream))
                                {
                                    ZipEntry ent = zip["ProcessingReport.xml"];
                                    ent.Extract(Server.MapPath("~/tmp"));
                                }
                            }

                            XPathDocument        myXPathDoc = new XPathDocument(Server.MapPath("~/tmp/ProcessingReport.xml"));
                            XslCompiledTransform myXslTrans = new XslCompiledTransform();
                            myXslTrans.Load(Server.MapPath("~/App_Docs/validation.xsl"));
                            using (XmlTextWriter myWriter = new XmlTextWriter(Server.MapPath("~/tmp/result.html"), null))
                            {
                                myXslTrans.Transform(myXPathDoc, null, myWriter);
                            }

                            Response.ContentType = "text/html";
                            Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + "result.html" + "\"");
                            Response.TransmitFile(Server.MapPath("~/tmp/result.html"));
                            Response.End();
                            Response.Close();
                        }
                        catch { }
                    }
                    //end attempt

                    Response.ContentType = "application/x-unknown";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + aa.RESPONSE_TXT + "\"");
                    Response.BinaryWrite(aa.RESPONSE_FILE);
                    Response.End();
                    Response.Close();
                }
                else
                {
                    if (aa.RESPONSE_TXT != null)
                    {
                        lblMsg.Text = aa.RESPONSE_TXT;
                    }
                    else
                    {
                        lblMsg.Text = "No validation details because submission succeeded.";
                    }
                }
            }
        }