0

我想访问 RDL 以获取 PDF 格式的报告。我有

    static void Main()
    {
        string pdfOutputFIleName = @"C:\Development\testoutputAsPdf.pdf";
        var urlAsPdf = @"http://serverName/ReportServer/Reserved.ReportViewerWebControl.axd?ExecutionID=xxx&Culture=1033&CultureOverrides=False&UICulture=9&UICultureOverrides=False&ReportStack=1&ControlID=yyy&OpType=Export&FileName=Bug+Status&ContentDisposition=OnlyHtmlInline&Format=PDF";

        var client = new WebClient();
        client.UseDefaultCredentials = true;

        //client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
        client.Headers.Add("Content-Type", "application/pdf");

        Process(client, urlAsPdf, pdfOutputFIleName);

        Console.Read();
    }

    private static void Process(WebClient client, string url, string outputFileName)
    {
        Stream data = client.OpenRead(url);
        using (var reader = new StreamReader(data))
        {
            string output = reader.ReadToEnd();
            using (Stream s = File.Create(outputFileName))
            {
                var writer = new StreamWriter(s);
                writer.Write(output);
                Console.WriteLine(output);                                        
            }
        }
    }

该 URL 在我的浏览器中运行良好。程序运行。当我打开 PDF 时,我在 Adob​​e 中收到错误消息:

打开此文档时出错。文件已损坏,无法修复。

4

1 回答 1

1

由于您已经指定了输出文件名和要读取的 url,也许您可​​以使用WebClient.DownloadFile(string address, string filename)member.

private static void Process(WebClient client, string url, string outputFileName)
{
    client.DownloadFile(url, outputFileName);
}
于 2013-09-13T22:21:31.307 回答