/// <summary> /// Processes HTTP Web requests to export SVG. /// </summary> /// <param name="context">An HttpContext object that provides references /// to the intrinsic server objects (for example, Request, Response, /// Session, and Server) used to service HTTP requests.</param> internal static void ProcessExportRequest(HttpContext context) { if (context != null && context.Request != null && context.Response != null && context.Request.HttpMethod == "POST") { HttpRequest request = context.Request; // Get HTTP POST form variables, ensuring they are not null. string filename = request.Form["filename"]; string type = request.Form["type"]; int width = 0; string svg = request.Form["svg"]; if (filename != null && type != null && Int32.TryParse(request.Form["width"], out width) && svg != null) { // Create a new chart export object using form variables. Exporter export = new Exporter(filename, type, width, svg); // Write the exported chart to the HTTP Response object. export.WriteToHttpResponse(context.Response); // Short-circuit this ASP.NET request and end. Short-circuiting // prevents other modules from adding/interfering with the output. HttpContext.Current.ApplicationInstance.CompleteRequest(); context.Response.End(); } } }
public ActionResult Export(string filename, string type, string svg, int width = 0) { if (filename != null && type != null && svg != null) { // Create a new chart export object using form variables. Exporter export = new Exporter(filename, type, width, svg, "Segoe UI"); // Write the exported chart to the HTTP Response object. export.WriteToHttpResponse(HttpContext.Response); // Finish request Response.OutputStream.Flush(); HttpContext.ApplicationInstance.CompleteRequest(); } return new EmptyResult(); }