Home » excel » c# – Automatically open file after downloading in Silverlight 4

c# – Automatically open file after downloading in Silverlight 4

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am creating an excel spreadsheet server side and downloading to the client via a Silverlight front-end. It is started by the user clicking a button and being presented with a SaveFileDialog. Once the user enters a file name then silverlight starts an asynchronous call to a web service and when finished returns a byte array which is written to wherever the user requested to save it. This all works fine.

How do I then automatically open this file on the client’s PC?

How to&Answers:

You Don’t or COM Interop

The ‘standard’ way of doing this in C# is ‘Process.Start(path)’. This is not allowed in Silverlight for good solid security reasons unrelated to your scenario.

In theory you could use COM Interop to open a document provided your Silverlight 4 application is running ‘Out of Browser’ or your Silveright 5 (Beta) application has the new advanced permissions. The trouble here is you don’t get the file path back from SaveFileDialog so you won’t know what path to pass to the COM Interop Open command. You might be able to ‘get hacky with it’ (e.g. searching based on file name and creation time stamp)…

Reference
http://www.itwriting.com/blog/2159-silverlight-4-with-com-can-do-anything-on-windows.html
http://justinangel.net/CuttingEdgeSilverlight4ComFeatures