public JsonResult Save(SqlReport sqlReport) { sqlReport.ReportName += ".sql"; SaveFile(sqlReport); return new JsonResult {Data = new {success = true}}; }
private void SaveFile(SqlReport sqlReport) { var path = BaseReportConfig().ReportTemplateRoot + sqlReport.DB + "." + sqlReport.ReportName; // Delete the file if it exists. if (System.IO.File.Exists(path)) { // Note that no lock is put on the // file and the possibility exists // that another process could do // something with it between // the calls to Exists and Delete. System.IO.File.Delete(path); } // Create the file. using (FileStream fs = System.IO.File.Create(path)) { Byte[] info = new UTF8Encoding(true).GetBytes(sqlReport.Sql); // Add some information to the file. fs.Write(info, 0, info.Length); } }