コード例 #1
0
        public void  ProcessRequest(HttpContext context)
        {
            const string TEMPLATE_FOLDER = @"";
            const string SCHEMA_TEMPLATE_FILENAME = "schema.docx";

            byte[] binWordFile = null;
            string responseFileName = string.Empty;

            try
            {
                string id = context.Request.QueryString["id"];

                if (string.IsNullOrEmpty(id))
                {
                    throw new Exception("Id paramter is invalid.");
                }

                Schema schemaData = getSchemaData(id);
                if (schemaData == null)
                {
                    throw new Exception("SchemaData is null.");
                }


                WordHelper wordHelper = new WordHelper();

                string templateLocation = Path.Combine(context.Server.MapPath(TEMPLATE_FOLDER), SCHEMA_TEMPLATE_FILENAME);

                binWordFile = wordHelper.CreateWordDocument(schemaData, templateLocation);

                responseFileName = getFileName(schemaData.Title, id);
            }
            catch (Exception ex)
            {

                context.Response.Clear();
                context.Response.Output.WriteLine("ERROR");
                context.Response.Output.WriteLine(ex.Message);
                if (ex.InnerException != null)
                {
                    context.Response.Output.WriteLine("<br />");
                    context.Response.Output.WriteLine(ex.InnerException.Message);
                }
                context.Response.End();
            }

            context.Response.Clear();
            context.Response.ContentType = "x-world/x-vrml";
            context.Response.AddHeader("Content-Disposition", "attachment;filename=" + responseFileName);
            context.Response.AddHeader("Content-Length", binWordFile.Length.ToString());
            context.Response.OutputStream.Write(binWordFile, 0, binWordFile.Length);
            context.Response.End();

        }