asp.net Silverlight Batch upload control implementation method

Source: Internet
Author: User
Tags silverlight

<summary>
Status of the file
</summary>
Internal enum Filestatus
{
<summary>
Ready, waiting to be uploaded.
</summary>
Ready = 0,
<summary>
It's crossing.
</summary>
uploading = 1,
<summary>
Upload successful
</summary>
Success = 2,
<summary>
Exception occurred in upload
</summary>
Error = 3,
<summary>
Upload operation aborted by user
</summary>
Cancel = 4,
<summary>
has been deleted by the user
</summary>
Delete = 5
}

Principle
using Silverlight to achieve multiple-choice batch upload, using the interaction with the Web page effects to control the display, and packaging it into ASP tutorial. NET Server control.
Overall structure

First the user enters the page, executes the server-side code of the bulk upload control, generates the HTML code (including Silverlight's HTML code, and completes the
initialization of Silverlight). The user selects the file on Silverlight and starts uploading, then uses Silverlight to access the current page, at the address
With the indicator variable to tell the server that this is an upload request, in the batch upload control server to determine whether to upload the request, if the text
Operation, after the completion of the display upload results (success or abnormal), the Silverlight end of the acquisition decision next action (transfer the rest of the current file)
Divide, transfer the next file, transfer end, and so on, and call the JavaScript method to update the display information of the page, but also invoke the JavaScript
method to postback a service-side event with a postback.
Interface

The control will initially display only an "Upload" button, click to show the floating layer, click "Select Files" pop-up File selection box, support multiple selection, select the end
BI Click "Upload file" upload, upload finished click "OK" to return.

Silverlight implementation of the end
The
Silverlight display in HTML is actually a <object></object>, Structure similar to:
<object id= ' obj ' data= ' data:application/x-silverlight-2, ' type= ' Application/x-sil Verlight-2 ' >
   &nb sp;       
<param name= ' background ' value= ' W Hite '/>            
<param name= ' minruntimeversion ' value= ' 3.0 '/>
<param name= ' AutoUpgrade ' Valu E= ' false '/>
</object>
Where source represents the path to the xap file generated by Silverlight compilation; minRuntimeVersion represents the client's silverlight< /c4> minimum run version, set here to
Version 3.0, lower than the 3.0 can not normally run the batch upload control; autoupgrade Indicates whether Automatic Updates are turned on, where Automatic Updates are turned off; windowless
Indicates whether Silverlightcan be obscured by other HTML elements, which are set to be obscured; InitParams represents a custom parameter and can be multiple to amuse
Number, the parameters used in the control are:
ClientID: The server control identifier generated by the ASP.net tutorial for the bulk upload control , used for unique identification.
Filter: FileName filter string, shaped like "picture file (*.gif;*.jpg) |*.gif;*.jpg"
Filemaxcount: The maximum number of uploaded files, the empty expression is not limited
Filemaxlength: Single file maximum length, unit byte, null representation not Limited
Showsubmit: Do you want to display the OK button
Datapacketsize: The size of each packet sent at the time of upload, KB
Subdirectoryname: The subfolder name where the uploaded file is stored in the temporary folder

The XAML file is relatively simple, as follows:

<grid width= "background=" "#f0f8f0" layoutupdated= "grid_layoutupdated" >
        <button content= "Select File" height= "horizontalalignment=" "left" x:name= "Btnchoose" fontfamily= "Arial,simsun"
Fontsize= "verticalalignment=" "Top" width= "margin=" "2,3,0,0" click= "Btnchoose_click"/>
        <button content= "Upload file" height= "horizontalalignment=" "left" x:name= "Btnupload" fontfamily= "Arial,simsun"
Fontsize= "verticalalignment=" "Top" width= "margin=" "83,3,0,0" click= "Btnupload_click"/>
        <button content= "OK" height= "horizontalalignment=" "left" x:name= "Btnok" fontfamily= "Arial,simsun"
Fontsize= "verticalalignment=" "Top" width= "margin=" "164,3,0,0" click= "Btnok_click"/>
    </grid>

is three buttons, "Select File" "Upload file" "OK".

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.