About ASP. NET Import and Export (2)

Source: Internet
Author: User

Com. Urp. Command. fileframework (2)

The uploadfileframe function was implemented yesterday. Basically, the upload function is complete. The download process continues today. Search on Google. There are not a few articles on ASP.net download, so there is no need to discuss how to do it. In JSF, downloading is implemented by modifying the response header. Think about it. Asp.net should be able to do it in this way, and I found the relevant article. There is a blog on the site. Address: Workshop :)

Java code:

Httpservletresponse response = (httpservletresponse) getfacescontext (). getexternalcontext (). getresponse ();

Response. Reset ();

Response. setcontenttype ("application/vnd. MS-excel ");

Response. setheader ("content-disposition", "attachment; filename =" + downloadfile. getfileapiname ());

Response. setcontentlength (baos. Size ());

SOS = response. getoutputstream ();

Baos. writeto (SOS );

SOS. Flush ();

 

C # code:

_ Response. Clear ();

_ Response. contenttype = _ fileapi. contenttype;

_ Response. addheader ("content-disposition", "attachment; filename =" + _ fileapi. filename );

_ Response. writefile (_ fileapi. Path );

_ Response. Flush ();

_ Response. End ();

I found that Java and. NET are incredibly similar.

Note: 1

The Code was originally written at the Controller layer, and now it is decided to put it in downloadfilefram. To do this, you only need to call an execute statement to complete the task :), but note that, you need to upload an httpcontext. current. response comes in. We also found that yesterday's design had some problems. In fact, there is no need to transfer a filetype In the constructor of the excelfile class. The excelfile class must be used to operate Excel files, and the file type is also fixed.

Note 2

Ifileapi is constructed by using the contenttype of httppostedfile during file upload, but the file is downloaded using fileinfo. extension. Therefore, we re-wrote a downloadapifacloud, which is used to construct ifileapi In the downloaded file, and added the contenttype attribute in ifileapi. Why not use a simple factory, it is because you may need to read the XML file information when constructing it in the future, and configure the temporary directory for upload and download through XML. To allow users to select the configuration method, abstract factory may be used as the parameter. Therefore, writing another confingfactory may also be incorrect.

Note 3

The ifileapi class stores filetype and contenttype attributes related to the specific file type. The localfile class has a path attribute unrelated to the specific file type. Simple file writing and reading are not related to the file type and are implemented in localfile. So there should be another class to implement ifileapi to process upload and download when the file type cannot be identified.

The class diagram of the appearance layer is modified as follows:

 

Modify the class diagram of the filetype package as follows:

The sequence diagram of the download process is as follows:

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.