예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var reportTemplateName = Request.Params["TEMPLATE_NAME"];
            var ReportNumber       = Request.Params["REPORT_NUMBER"];
            var RGReportID         = Request.Params["REPORT_ID"];
            var cellNo             = Request.Params["CELL_NO"];

            //date is expected in dd/MM/yyyy format from the url


            if (string.IsNullOrEmpty(reportTemplateName))
            {
                return;
            }

            var generationInfo = GetDocumentGenerationInfo("AddressStickerGenerator", "1.0", GetDataContext(),
                                                           reportTemplateName, false);

            var addressStickerGenerator
                = new AddressStickerGenerator(generationInfo);

            byte[] result   = addressStickerGenerator.GenerateDocument();
            var    filePath = WriteOutputToFile("AddressStickerReport" + DateTime.Now.ToString("SSMIHH") + ".docx", result);

            using (var wordDocument = WordprocessingDocument.Open(filePath, true))
            {
                wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document);
                var mainDocumentPart = wordDocument.MainDocumentPart;
                var document         = mainDocumentPart.Document;
                // Clean up: The user will appreciate a clean document!
                var helper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri);
                helper.RemoveContentControlsAndKeepContents(document);
                document.Save();
            }

            //download the file to the user

            string filename = "AddressStickerReport.docx";

            Response.ContentType = "application/ms-word";
            Response.AddHeader("content-disposition", "attachment; filename=" + filename);
            Response.TransmitFile(filePath);
            Response.Flush();

            //clean up the file
            File.Delete(filePath);
            Response.End();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var reportTemplateName = Request.Params["TEMPLATE_NAME"];
            var ReportNumber = Request.Params["REPORT_NUMBER"];
            var RGReportID = Request.Params["REPORT_ID"];
            var cellNo = Request.Params["CELL_NO"];

            //date is expected in dd/MM/yyyy format from the url

            if (string.IsNullOrEmpty(reportTemplateName))
                return;

            var generationInfo = GetDocumentGenerationInfo("AddressStickerGenerator", "1.0", GetDataContext(),
                                        reportTemplateName, false);

            var addressStickerGenerator
                = new AddressStickerGenerator(generationInfo);

            byte[] result = addressStickerGenerator.GenerateDocument();
            var filePath = WriteOutputToFile("AddressStickerReport" + DateTime.Now.ToString("SSMIHH") + ".docx", result);

            using (var wordDocument = WordprocessingDocument.Open(filePath, true))
            {
                wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document);
                var mainDocumentPart = wordDocument.MainDocumentPart;
                var document = mainDocumentPart.Document;
                // Clean up: The user will appreciate a clean document!
                var helper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri);
                helper.RemoveContentControlsAndKeepContents(document);
                document.Save();
            }

            //download the file to the user

            string filename = "AddressStickerReport.docx";
            Response.ContentType = "application/ms-word";
            Response.AddHeader("content-disposition", "attachment; filename="+filename);
            Response.TransmitFile(filePath);
            Response.Flush();

            //clean up the file
            File.Delete(filePath);
            Response.End();
        }