Link to home
Start Free TrialLog in
Avatar of david-shm
david-shm

asked on

How to save a byte array to a file from silverlight

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.
Avatar of EDDYKT
EDDYKT
Flag of Canada image

>>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?


Don't think you can bypass this because is security issue.
Can you bring up SaveFileDialog when user click the button?
Another way to save to Isolated Storage and i don't think this is the way you want


Avatar of david-shm
david-shm

ASKER

Hello,

No. I tryed to show a SaveFileDialog when the user clicks the button but the exception still happens.
I thought that was possible...
don't take a break point on the line DialogSave.ShowDialog() or before, break point after the line
DialogSave.ShowDialog()

SaveFileDialog DialogSave = new SaveFileDialog();

            if (DialogSave.ShowDialog() == true)
            {
               ...
            }
Hello EDDYKT,

The excution thread doesn't reach any point beyond the if, because DialogSave.ShowDialog() throws an exception.
Kind regards,

David
Thing is calling SaveFileDialog should be only user initiated, so basicaly just store byte array in your app when it arived and dysplay dialog on bytes recived callback. With button that calls SaveFiledialog.

This article displays another way of doing your task: http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx
ASKER CERTIFIED SOLUTION
Avatar of EDDYKT
EDDYKT
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

I could resolve it based on this: http://stackoverflow.com/questions/2177968/how-to-save-a-byte-array-to-a-file-from-silverlight
But your suggestion for the callback is a very good idea. Let me try it and I'll let you know ASAP.
>>I could resolve it based on this: http://stackoverflow.com/questions/2177968/how-to-save-a-byte-array-to-a-file-from-silverlight

don't think you can call DialogSave.ShowDialog()  on your callback
Util it's initiated by user button click and no iterfaces used to get to SaveFileDialog