Silverlight and MVC best file download solution

Source: Internet
Author: User
Tags silverlight

(a) Foreword

Currently, downloading files in Silverlight usually takes two ways to download files:

1, the client through the SaveFileDialog class for file downloads, server use byte array (byte[]) for data delivery.

2, the client through access to the service side of the general processing file (. ashx) to download the file.

For the 1th way to download, the main flaw is: Click to download, pop-up SaveFileDialog dialog box incredibly no filename!!! (You must have your own handwritten filename, and Silverlight has yet to be improved). The SaveFileDialog related properties and methods in Silverlight are as follows:

public sealed class 

SaveFileDialog
    {public
         savefiledialog ();
         public string Defaultext {get; set;}
         public string Filter {get; set;}
         public int FilterIndex {get; set;}
         public string Safefilename {get;}
         Public Stream OpenFile ();
         public bool? ShowDialog ();
    }

For the 2nd way to download, it is easy to expose the relevant information (processing file pages are sometimes directly in the address bar to display relevant information).

Silverlight mainly through HtmlPage.Window.Navigate (new Uri (URL)) to access general processing files, general processing file Download (response to execute);

So far, the development of Huawei Hummer Project has been more than half a year, mainly in the MVC and Silverlight development. Therefore, for the current project, I tried to invoke the MVC action in Silverlight to download, such as the following content will be around the topic to explain (at present, the wood has been updated to the project, only my Notebook design).

(ii) Related class diagrams and Filedownloadresult

In MVC, the action mainly takes the ActionResult as the return result, and then calls the ActionResult Executeresult () method to perform the related operation. However, the main actionresult for file operations so far are Filestreamresult, Filecontentresult, and Filepathresult, which are not easy to use (for file downloads). Therefore, I intend to use the Filedownloadresult class for file download related operations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.