When I print a report, I create a html page that the user can print. Now, there was a need to backup these reports. So I had to find out how to save the html code to a file. The solution was very simple:
System.Net.WebClient client = null;
try
{
client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.UTF8;
client.Headers = new System.Net.WebHeaderCollection();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;)");
string url = Request.Url.ToString().Replace("administration","reports");
url = url.Replace("reports.aspx", "reportprint.aspx?reportGuid=" + guid);
//string html = client.DownloadString(url);
string path = ConfigurationManager.AppSettings["ArchivePath"] + guid +".html";
client.DownloadFile(url, path);
}
catch (Exception r)
{
string test = r.Message;
}
finally
{
client.Dispose();
}
The url string had to be the full url, no relative url's. So I took the url of the current page and replaced 2 parts of the url to make the correct url. The path where the report are saved is stored in the config file.