views:

1566

answers:

7

I need to write a web application that allows the client to download a file from the server, so far so good, but the file must be kind of encoded, so i need to decode it on the client and write it on a file on the client's PC.

Can i do this using Silverlight? and how?

If it is not possible, there is another way to do it?. Any suggestions?

Thanks

Edit: As exposed for Brian Genisio, i can ask for user permision to save the file, so i think that the open and save Dialogs are ok for my case. But in case that that's not enough, is there a way to, with or without user interaction, to save the file outside of the isolated storage, for example emulating a new download for the user?

+2  A: 

You can use IsolatedStorageFile Class for this using silverlight.

Another link: How to Read and Write files in the Isolated Storage?

Gulzar
+3  A: 

You cannot do this for security reasons:

Silverlight-based applications do not use the file system of the operating system and are restricted to using isolated storage to persist and access files, so this namespace [System.IO] does not provide any additional functionality. For more information about how Silverlight-based applications use isolated storage, see Isolated Storage.

If possible, you might want to shift it such that the server does the encoding and the file is made available for download in a traditional manner.

If you're encoding for privacy/security consider offering the download only on a secure protocol (HTTPS using SSL).

Ben S
+6  A: 

In Silverlight 3.0, you will have access to read and write files via the OpenFileDialog. In Silverlight 2.0, you have access to Isolated Sotrage, which will let you save to a sandbox. You will probably never have full access to the file system without user permission, though.

Brian Genisio
A: 

Another option (not elegant but works) could be to perform a ping pong using services:

  • Get the file from the server.
  • Perform the encoding /transformation you need on the client side.
  • Send it to the server again using a WCF service, store it in session.
  • Call a javascript method from SL that will make a request to a custom HTTP hanlder.
  • That custom HTTP hanlder would return the file that was in session as an attachment (first time the nasty bar from IE would appear... you are going to download something...).

My case is a bit simpler, in my application I needed to export a DB Diagram to JPEG and to perform an export as well to an HTML report, I used that approach (ping pong :)).

If you want to take a look:

http://www.dbschemaeditor.com

HTH Braulio

Braulio
A: 

With Silverlight 4, you can do this in a primitive way by using AutomationFactory to automate a FileSystemObject.

see: http://justinangel.net/CuttingEdgeSilverlight4ComFeatures#BlogPost=CuttingEdgeSilverlight4ComFeat

Chris J
A: 

i think its better do this in primitive way too and get server file TEXAS

texas
A: 

i think its better use IsolatedStorageFile TEXAS

texas