Beispiel #1
0
    private void LoadForm(string countryCode, string fileName, string generationType, string fileType, string period)
    {
        DataSet dsData = new DataSet();


        if (fileType.Trim() != "xml")
        {
            dsData = DBReadManager.GeneratedFileDownload(countryCode, period, Convert.ToBoolean(generationType));
            if (dsData != null)
            {
                gvCBC.Bind(dsData);
                ExportToExcel(fileName, period);
            }
        }
        else
        {
            if (Convert.ToBoolean(generationType))
            {
                dsData = DBReadManager.GetOutgoingCBCReports(countryCode, period);
            }
            else
            {
                dsData = DBReadManager.GetNewIcomingCBCR(countryCode, period);
            }

            if (dsData != null)
            {
                var doc = new XmlDocument();
                doc.LoadXml(dsData.Tables[0].Rows[0][0].ToString());
                using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                {
                    XmlTextWriter writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

                    doc.WriteTo(writer);
                    writer.Flush();
                    Response.Clear();
                    byte[] byteArray = stream.ToArray();
                    Response.AppendHeader("Content-Disposition", "attachment;" + string.Format("filename ={0}_{1}.xml", fileName, period));
                    Response.AppendHeader("Content-Length", byteArray.Length.ToString());
                    Response.ContentType = "application/octet-stream";
                    Response.BinaryWrite(byteArray);
                    Response.Flush();
                    Response.End();
                    writer.Close();
                }
            }
        }
    }