Uploadify + C # instance

Source: Internet
Author: User

When we put it in our system, there are several points to change:

1: uploadify.css

Because the background of the button style he canceled is by default.../img /...

So we need to change it based on your needs.

. Uploadify-queue-item. cancel {
Background: url ('/uploadify/uploadify-cancel.png') 0 0 no-repeat;
.....
}

2: The page generally references compressed js

I used jquery. uploadify. min. js.

However, some prompts are in English, so find some prompts and change them to the corresponding Chinese.

In the bottom

3: The Page code is as follows:

 


<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default3.aspx. cs" Inherits = "Default3" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Link href = "uploadify/uploadify.css" rel = "stylesheet" type = "text/css"/>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Input id = "file_upload_1" type = "file"/>
<Input id = "ibtnSumbit" type = "button" value = "Submit"/>
</Form>
</Body>
<Script src = "Scripts/jquery-1.4.1.min.js" type = "text/javascript"> </script>
<Script src = "uploadify/jquery. uploadify. min. js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("# File_upload_1"). uploadify ({
Uploader: '/UploadHandler. ashx', // Save the background Code address of the file after uploading the file
Swf: '/uploadify/uploadify.swf', // feature flash Address
Width: 90, // Length
Height: 20, // height
QueueSizeLimit: 6, // limit the number of uploaded files
CheckExisting: '/uploadify/check-exists.php', // check whether the file contains the background Code address
ButtonText: 'click to upload file ',
FileSizeLimit: '1000kb', // size limit of the file to be uploaded, measured in 100 KB
Auto: false, // automatic upload when a file is added to the queue
Multi: true, // If set to true, multi-File Upload is allowed.
FileTypeExts: '*. gif; *. jpg; *. png', // specifies the suffix of the file to be uploaded.
FileDesc: 'Only format (. JPG,. GIF,. PNG) ', // The text displayed in the file type drop-down menu at the bottom of the browser window
OnQueueComplete: function (){
Alert ('upload successful ');
// After a successful upload, the upload button cannot be invalidated (as required)
$ ("# File_upload_1"). uploadify ('disable', true );
// The submit button is invalid.
$ ("# IbtnSumbit"). unbind ("click ");
}
});
$ ("# IbtnSumbit"). bind ("click", function (){
// Dynamically call upload events
$ ("# File_upload_1"). uploadify ("upload ","*");
});
});
</Script>
</Html>

The UploadHandler. ashx code is as follows:

<% @ WebHandler Language = "C #" Class = "UpLoader" CodeBehind = "~ /App_Code/UpLoader. cs "%>

~ /App_Code/UpLoader. cs code is as follows:


Using System;
Using System. Web;

/// <Summary>
/// Summary of UpLoader
/// </Summary>
Public class UpLoader: IHttpHandler
{
Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
Context. Response. Charset = "UTF-8 ";

HttpPostedFile file = context. Request. Files ["Filedata"];
String uploadPath = HttpContext. Current. Server. MapPath (@ "/images/") + System. DateTime. Today. to1_datestring () + "/";

If (file! = Null)
{
If (! System. IO. Directory. Exists (uploadPath ))
{
System. IO. Directory. CreateDirectory (uploadPath );
}
File. SaveAs (System. IO. Path. Combine (uploadPath, file. FileName ));
Context. Response. Write ("1 ");
}
Else
{
Context. Response. Write ("0 ");
}
}

Public bool IsReusable
{
Get
{
Return false;
}
}

}

 

Now you can run the Code directly.


 

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.