Search code examples
c#-4.0silverlight-4.0silverlight-oob

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.


Solution

  • 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.