Asp.net multi-choice File Upload solution in batches, asp.net multi-Choice

Source: Internet
Author: User

Asp.net multi-choice File Upload solution in batches, asp.net multi-Choice

Multiple-choice File Upload is already very large. If you select more files, you may need to compare which one is more appropriate. It is most important to integrate it into the project for more convenient use. Many of the multiple-choice uploads are basically called swf files. It is very convenient to use flash or flex to develop a multi-choice upload function. For example, the built-in FileReferenceList object in flex supports multiple file selections, this is much more convenient. Next we will talk about a multi-choice upload function developed based on flex.
The main functions are as follows:
1. Select multiple files to upload and display the upload progress of a single file
Ii. display the overall upload progress of all files
3. display the total size of all uploaded files
4. You can delete any selected file (press Ctrl or Shift) before uploading)
5. the swf file generated by the ASP. NET page call is asynchronously uploaded to the server.

Let's take a look at the demo, as shown below:

The functions are roughly the same as above. The following describes ASP. how to call in. NET, I will not detail the code in FLEX here, there are not many code in FLEX, the article will be provided for download later, you can use flex3.0 or 4.0 to open and run.
Here is a description, that is, to ensure the correctness of the random multiple-choice deletion, you need to sort the selected index items in descending order and delete them from the maximum array each time, this prevents the index from exceeding the limit during cyclic deletion.

Function deleteItem (): void {var selectItems: Array = process_list.selectedItems; var selectIndex: Array = process_list.selectedIndices; selectIndex = selectIndex. sort (2); // The index is sorted in descending order var iCount: int = selectItems. length; var sizeMum: Number = 0; for (var I: int = 0; I <iCount; I ++) {info. splice (selectIndex [I], 1); fileRef. fileList. splice (selectIndex [I], 1); // The removed selection items are removed from large to small by index, so that the index is not exceeded during the removal process} for (var j: number = 0; j <fileRef. fileList. length; j ++) {sizeMum + = fileRef. fileList [j]. size;} process_list.dataProvider = info; tip_txt.text = "Total" + fileRef. fileList. length + "Files" + (sizeMum/(1024*1024 )). toFixed (4 ). toString () + "MB"; if (info. length <= 0) {delete_btn.enabled = false ;}}

Actually, it is relatively simple to create a new SWF file generated on the ASP tutorial page X. The file name generated here is upload.swf, which is loaded using the methods in flex's built-in swfobject. js, as shown below:

<Html xmlns =" http://www.w3.org/1999/xhtml "> <Head> <title> No title page </title> <style type =" text/css tutorial "media =" screen "> html, body {height: 100% ;} body {margin: 0; padding: 0; overflow: auto; text-align: center; background-color: # ffffff ;}# flashContent {display: none ;} </style> <script type = "text/Webpage effects" src = "swfobject. js "> </script> <script type =" text/javascript "> var swfVersionStr =" 10.0.0 "; var xiSwfUrlStr =" playerProductInstall.swf "; var fla Shvars ={}; flashvars. url = "SaveFile. aspx? Param = ID | 100, NAME | test user "; var params ={}; params. quality = "high"; params. bgcolor = "# ffffff"; params. allowscriptaccess = "sameDomain"; params. allowfullscreen = "true"; var attributes = {}; attributes. id = "upload"; attributes. name = "upload"; attributes. align = "middle"; swfobject. embedSWF ("upload.swf", "flashContent", "587", "370", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes); func Tion uploadCompelete () {// after the operation is completed, such as page Jump or close the current page document. getElementById ('btnupload '). disabled = false;} function submitForm () {thisMovie ("upload "). uploadfile ();} function thisMovie (movieName) {if (navigator. appName. indexOf ("Microsoft ")! =-1) {return window [movieName];} else {return document [movieName];} function disabledButton () {document. getElementById ('btnupload '). disabled = true ;}</script> 

After all, it is not received and stored in the form of a file stream. Therefore, if you upload a large file, you can see that the page has been uploaded 100%, but the storage processing page will pause for a while, after receiving and storing the information, the front-end page will respond.
Another point to mention is that if the transmitted parameters contain Chinese characters, the config encoding format must be UTF-8, but the original system may be in gb2312 format, changing to UTF-8 may have an impact on the system. You can create a webconfig file separately and read a separate config file during upload.

The above is the code for uploading multiple files in batches in asp.net, hoping to solve the problems encountered when uploading multiple files in ASP. NET.

Related Article

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.