public string GenerateTemplate(string templateName, [FromBody] Dictionary <string, string> templateReplaceText) { try { var res = requestHandler.GetObjects(Request, templateName); if (res != null) { string templatePath = ((TemplateType)(((ObjectContent)res.Content).Value)).TemplatePath; var tempPath = blobhandler.CreateTemplate(Request, Convert.ToInt32(templateName.Split('_')[1]), templatePath, templateReplaceText); FileInfo fileInfo = new System.IO.FileInfo(tempPath.ToString()); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", fileInfo.Name)); HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString()); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); HttpContext.Current.Response.WriteFile(tempPath.ToString()); //HttpContext.Current.Response.BinaryWrite(btFile); HttpContext.Current.Response.End(); if (File.Exists(tempPath.ToString())) { File.Delete(tempPath.ToString()); } return(tempPath.ToString()); } } catch (Exception error) { return(error.Message); } return("S"); }