Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I am struggling to render a report in PDF in a folder in ssrs. I managed to render the report to my local however the PDF file is not downloading in the folder on my C drive. Any suggestions?

What I have tried:

C#
using System;
using System.IO;
using System.Web.Services.Protocols;
using myNamespace.MyReferenceName;

class Sample
{
    static void Main(string[] args)
    {
        ReportExecutionService rs = new ReportExecutionService();
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
        rs.Url = "http:myLocaladdress";

        // Render arguments
        byte[] result = null;
        string reportPath = "/TEST";
        string format = "PDF";
        string historyID = null;
        string devInfo = @"<deviceinfo><toolbar>False</toolbar></deviceinfo>";

        try
        {
            result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

            execInfo = rs.GetExecutionInfo();

            Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);


        }
        catch (SoapException e)
        {
            Console.WriteLine(e.Detail.OuterXml);
        }
        // Write the contents of the report to an PDF file.
        try
        {
            Byte[] results = rsExec.Render(format, deviceInfo, out extension, out mimeType, out encoding, out warnings, out streamIDs);
            FileStream stream = File.OpenWrite("C:\\T.pdf");
            stream.Write(result, 0, result.Length);
            Console.WriteLine("Result written to the file.");
            stream.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }

    }
}
Posted
Updated 25-Aug-16 21:56pm
v2
Comments
Richard Deeming 26-Aug-16 9:45am    
Are you getting any errors?

You're trying to save the file to the root of your system drive. You probably won't have access to do that unless you run your program "elevated" (right-click, "run as administrator"). Try saving to a folder within your user profile instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900