views:

454

answers:

1

Hello Everybody,

I have a SL 3 application connected to a WCF service. This service retrieves an array of bytes. I'd like to save that array as a pdf file using FileStream. The problem is that when the byte array is retrived, I get an exception when trying to show the SaveFileDialog because that action is initiated by the callback method and not from a user action, it seems. I'd like to know if there is any workaround for this. I already have the byte array, now I need to save it to a location specified by the user. No matter how... Any clue?

Thanks in advance.

+2  A: 

Are you wiring to the method completed event of your async method call? See this

http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx

Inside your call back method, you can implement the logic for writing to a file - first by opening the dialog, and then by getting the pointer to the file stream as shown below.

       try 
       {
           byte[] fileBytes = //your bytes here 
           SaveFileDialog dialog=new SaveFileDialog();

           //Show the dialog              
           bool? dialogResult = this.dialog.ShowDialog();  

           if (dialogResult!=true) return;


            //Get the file stream

            using ( Stream fs = ( Stream )this.dialog.OpenFile() )  
            {  
                fs.Write( fileBytes, 0, fileBytes.Length );  
                fs.Close();  

                //File successfully saved
            }  
        }  
        catch ( Exception ex )  
        {  
            //inspect ex.Message  
        }  
amazedsaint
Hi amazedsaint, I don't know what was wrong. I commented and then uncommented some code and then the dialog showed up ¿¿??But after that, I had some trouble to write the byte array but your response here was the solution. Thanks a lot!!