0

I am generating an ssrs report in my Silverlight application and I need to convert the ssrs report to RadPDFViewer control(telerik silverlight). So I am saving the pdf file in the project folder using WCF. Now i need to read the file again and bind it to Pdfviewer.

Saving happens asynchronously. How should I wait untill the file is saved and then read from the folder?

Also, can you please show me how to read the PDF as a Memory stream.

I run the following code unsuccessfully.

public byte[] ReturnPdf(string requestUrl) {
        HttpWebRequest req = null; var buf = new byte[1024];
        try
        {
                req = (HttpWebRequest)WebRequest.Create(requestUrl);

                req.Credentials = CredentialCache.DefaultCredentials;

                req.Method = "GET"; var objResponse = req.GetResponse();
                var stream = objResponse.GetResponseStream();
                if (stream != null){BinaryReader br = new BinaryReader(stream);
                        buf = br.ReadBytes(1024);
                } if
                (stream != null) stream.Close();

        }
        catch Exception e){}return buf;
}

private void button2_Click(object sender, EventArgs e)
{

        string baseUrl = "http://abc/ReportServer&rs:Command=Render&rs:ClearSession=true&rs:Format=PDF";

        const string nullString = ":isnull=true";


        byte[] o = ReturnPdf(baseUrl);

        byte[] bytes = new byte[1024];
        Stream s = new MemoryStream(bytes);

}
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
srikanth
  • 159
  • 3
  • 14

1 Answers1

2

Write PDF Stream:

Write PDF stream to response stream

You could check to see if the file has been written completely.

How to test if a file is currently being written to

Or this might help:

How to check for file lock?

Community
  • 1
  • 1
Marnee KG7SIO
  • 398
  • 4
  • 10
  • i have tried writhing the below code.. it still does not work. public byte[] ReturnPdf(string requestUrl) { HttpWebRequest req = null; var buf = new byte[1024];try{req = (HttpWebRequest)WebRequest.Create(requestUrl);req.Credentials = CredentialCache.DefaultCredentials; req.Method = "GET"; var objResponse = req.GetResponse(); var stream = objResponse.GetResponseStream(); if (stream != null){BinaryReader br = new BinaryReader(stream); buf = br.ReadBytes(1024); } if (stream != null) stream.Close();} catch Exception e){}return buf; } – srikanth Jun 15 '12 at 22:14
  • There is no exception.. i just do not receice the PDF file.. is there any other way to do it> – srikanth Jun 16 '12 at 22:58
  • Step through your code. Stream is null, maybe? Or PDF is null? Turn off pop-up blocker? – Marnee KG7SIO Jun 18 '12 at 03:12
  • 1
    You might use a combo of the free libaries PdfSharp and iTextSharp. iTextSharp to read the file into a PdfSharp document and then stream to the browser. – Marnee KG7SIO Jun 18 '12 at 03:31