Пример #1
0
        private void templatesList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (templatesList.SelectedValue == "-1" || selectedID == "")
            {
                return;
            }

            var report = GetSingleReport();

            if (report == null)
            {
                return;
            }

            var reportBuilder = new WordReportBuilder();

            var response = Page.Response;

            response.Clear();
            response.AddHeader("Content-Type", "application/octet-stream");
            response.AddHeader("Content-Disposition", "attachment;filename=" + templatesList.SelectedItem.Text + ".docx");

            reportBuilder.Create(response.OutputStream, report);
            response.End();
        }
Пример #2
0
        private string PrepareReport(int templateID)
        {
            var extension = GetReportExtension(templateID);
            var guid      = Guid.NewGuid();
            var link      = string.Format(@"~\temp_data\reports\{0}{1}", guid, extension);

            var reportPath = HttpContext.Current.Server.MapPath(link);

            FileStream fileStream;

            try
            {
                var dir = Path.GetDirectoryName(reportPath);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                fileStream = File.Create(reportPath);
            }
            catch
            {
                throw new Exception(string.Format("Не удалось создать файл {0} с расширением {1}, полный путь {2}", guid, extension, reportPath));
            }

            var reportBuilder = new WordReportBuilder();

            var report = GetSingleReport();

            if (report != null)
            {
                reportBuilder.Create(fileStream, report);
            }

            fileStream.Flush();
            fileStream.Close();

            return(link);
        }