My web application wishes to send a file as an attachment to an email. That is quite doable; all I must do is specify the path to the file. But prior to sending the file, the system must create the file- it is a rendered report. It matters not where it is saved, since it will be in an attachment. That being the case, I cannot figure out how to write this file. It works on my localhost but not when I run it on our company's development server. The error message is a 500 one; undescriptive and unknown.
This is part of the event handler that transpires when a user clicks a button to generate a report which will get emailed to her boss:
In this code snippet, ext is some variable three letter file extension and content is content is the returned value of executing Render on a ReportExecutionService object:
var rptPath = HttpContext.Current.Server.MapPath(string.Format("Report.{0}", ext));
//using (var fs = new FileStream(rptPath, FileMode.OpenOrCreate, FileAccess.Write))
using (var fs = File.Create(rptPath))
{
fs.Write(content, 0, content.Length);
}
...at this point it throws an Exception. I granted the NetworkService account write privileges via right-clicking on the file system of the development server and relaxing permissions to that account. I also relaxed security in IIS 6, which hosts the web application on the development server. What else needs to be done? I merely wish to spit a .pdf file to the root web directory.