Prabhakaran
Prabhakaran

Reputation: 1337

How to open word/pdf in silverlight4?

I am using silverlight4 app ,i have a requirement like to store the word/pdf file in the database(sqlserver) and successfully i did that and now i want to open the stored file using the corresponding application with my extension.Iam not using OOB ,it that possible to open the file or to store the file in a user selected location.Can anyone plz help me on this?

Thanks in advance.

Upvotes: 0

Views: 1703

Answers (3)

dipak
dipak

Reputation: 2033

I would suggest create one .aspx page or HTTPHandler then override ProcessRequest method.

public void ProcessRequest(HttpContext context)
{
   //database table or PDF/word file
   System.IO.MemoryStream mstream = GetData(); 
   //Convert the memorystream to an array of bytes. 
   byte[] byteArray = mstream.ToArray();         

    string fileName= "test.pdf";
    context.Response.Clear();

    context.Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
    context.Response.ContentType = "application/octet-stream";
    context.Response.BinaryWrite(byteArray); 
    context.Response.Flush();
    context.Response.End();
}

Your Silverlight application will act just like normal client and makes http Request using

<HyperlinkButton Content="Click Me" NavigateUri="Download.aspx?id=fileid" />

in above code

  context.Response.AppendHeader("content-disposition", "attachment;

tells browser to prompt for OPEn/Save dialog.

I hope this will work.

Upvotes: 1

Chris Anderson
Chris Anderson

Reputation: 8369

I make use of the Acrobat Reader plugin to do the displaying for me. It does require a different method depending on whether your application is running inside or outside the browser (I check if the application is running inside the browser and change the means of display accordingly). If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/9781430272076/.

Hope this helps...

Chris

Upvotes: 0

Maheep
Maheep

Reputation: 5605

Simply provide a HTML hyperlink to you word/pdf file. As soon as user clicks the link the open/save dialog will open at client browser. For this you can use something like this:

<HyperlinkButton Content="Click Me" NavigateUri="filep URL" />

Upvotes: 0

Related Questions