How to download file from a physical location in Silverlight? urgent.........
-
Hi all, I want to download xml or any other file from physical location like C:\Documents and Settings\All Users\Documents\Test.xml and open a Save Dialog box to allow user to save it in desired location Is it possible in Silverlight 2.0? Can we do it in xaml.cs file? If yes then plz share the code with me..... Its very urgent......... Thanks in advance,
-
Hi all, I want to download xml or any other file from physical location like C:\Documents and Settings\All Users\Documents\Test.xml and open a Save Dialog box to allow user to save it in desired location Is it possible in Silverlight 2.0? Can we do it in xaml.cs file? If yes then plz share the code with me..... Its very urgent......... Thanks in advance,
salon wrote:
Is it possible in Silverlight 2.0?
Opening a file you can do using the OpenFileDialog class, so the user effectively needs to give permission first. Saving a file, no, not in Silverlight 2.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hi all, I want to download xml or any other file from physical location like C:\Documents and Settings\All Users\Documents\Test.xml and open a Save Dialog box to allow user to save it in desired location Is it possible in Silverlight 2.0? Can we do it in xaml.cs file? If yes then plz share the code with me..... Its very urgent......... Thanks in advance,
Another option (not elegant but works) could be to perform a ping pong using services: - Send your file 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...). 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 :)), I could set an attribute (attachment) and IE would ask me to save the JPEG as a file. If you want to take a look at how it behaves: http://www.dbschemaeditor.com HTH Braulio
/// ------------------------- Braulio Díez DBSchemaEditor.com Free Silverlight based DB Schema Modeling Tool /// -------------------------
-
Another option (not elegant but works) could be to perform a ping pong using services: - Send your file 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...). 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 :)), I could set an attribute (attachment) and IE would ask me to save the JPEG as a file. If you want to take a look at how it behaves: http://www.dbschemaeditor.com HTH Braulio
/// ------------------------- Braulio Díez DBSchemaEditor.com Free Silverlight based DB Schema Modeling Tool /// -------------------------
-
If you don't mind ! Can you share the code/link to solution so that I get a clear picture of the entire thing? I have searched for the above solution but not getting any way............. Please help me....
I don't have alink with the whole solution, but the pieces and what I implemented on my project. Let's go step by step: About the solution: It's a workaround, SL cannot do that, what we do then is to workaround it using ASP .net / Javascript (in ASP .net it's possible to return a file to client as an attachment). In my case: --> I have an XML file on my client side (that represents the database diagram), it could be whatever that can be serializable. --> I have an WCF service that accepts as input parameter that XML file, I send a call from SL to the service (if you have question on this give me a shout and will try to find some tutorial about how to call services from SL). --> This service that I'm calling inherits the context from the ASP .net application, that is, we have the ASP .net session available, to enable this you only have to add to the header of your service class:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class RenderService
--> In my case I stored the XML file in a session variable in the server (so for that user we get the file in his session / memory). --> Once the Silverlight receives the callback from the service call (the service has been called successfully), I call from SL a javascript method:public void ShowDiagramImageRenderPopup() { System.Windows.Browser.HtmlPage.Window.CreateInstance("showReportDiagramPopup"); }
--> This javascript methods opens a popup that points to a URL (if I want it to download a file I just have to open a page in the same navigator, the only thing is that the custom HTTP Handler must return an "attacment").
// Show the report render popup, I'm calling an ASPX that has inside a refernce to an image generated by // a custom HTTP hanlder (the commented solution, was the one related to download an attachmen) function showReportDiagramPopup() { //http: //www.javascripter.net/faq/openinga.htm window.open("DiagramRenderPopup.aspx", "DatabaseDiagram", "scrollbars=yes, width=800,height=600", false); // NOT IN USE, rather using popup // Finally we are not going to use a popup, we just open the generated image as an attachment //window.location = "DiagramImageHandler.ashx" }
--> Ok, now let's go for the CUstom HTTP Hanlder "DiagramImageHandler.ashx", the main code s