Export Report to the File

This sample project shows how to export a report shapshot item to the file on the hard drive. For this purpose you can use the export REST command of the reportsnapshots commands group. As parameters, you need to specify the file item name and the export set with the export parameters. These parameters can be passed as the request post data.

var reportSnapshotKey = "897324aec5154c6fb102f47ff9267a42";

var url = "http://localhost:40010/1/reportsnapshots/" + reportSnapshotKey + "/export";
var requestRun = WebRequest.Create(url);
requestRun.Method = "PUT";
requestRun.ContentType = "application/x-www-form-urlencoded";

requestRun.Headers.Add("x-sti-SessionKey", sessionKey);
requestRun.Headers.Add("x-sti-DestinationItemKey", filefolderKey);

var postData = "{ 'FileItemName':'ExportReport.pdf', 'ExportSet':" +
"{ 'Ident':'Pdf', 'PageRange':{ },'EmbeddedFonts':false,'DitheringType':'None','PdfACompliance':true} }";
byte[] bytes = Encoding.GetEncoding(1251).GetBytes(postData);
Request(requestRun, postData);
var s = GetResponseResult(requestRun);


You can use the following methods to send the request to the server and get the requested result.

private void Request(WebRequest request, string postData)
{
var bytesCreateSnapshot = Encoding.GetEncoding(1251).GetBytes(postData);
request.ContentLength = bytesCreateSnapshot.Length;
using (Stream ws = request.GetRequestStream())
{
ws.Write(bytesCreateSnapshot, 0, bytesCreateSnapshot.Length);
ws.Flush();
}
}

private string GetResponseResult(WebRequest request)
{
var resp = request.GetResponse();
var respStream = resp.GetResponseStream();
if (respStream != null)
{
using (var stream1 = new StreamReader(respStream))
{
var s = stream1.ReadToEnd();
return s;
}
}
return null;
}


You can create the File Storage item in which you should specify a path and then use it as a destination for the export.

File Storage