Example of uploading a file in a file box (htmlinputfile)

Source: Internet
Author: User
1. On the ASPX page:
Drag an htmlinputfile object whose ID is file1 and an htmlinputbutton object whose ID is button1.
Double-click the button1 object to go to the event trigger method:
2. On the CS page: Protected   Void Button#serverclick ( Object Sender, eventargs E)
{
// Here, file1 is a file box (htmlinputfile );

// Get File Name: splits the value obtained by file1 into a string array according to '\', and assigns the last file name to arrfilename;
Arraylist arrfilename =   New Arraylist ();
Arrfilename. addrange (file1.value. Split ( ' \\ ' ));
String Filename = Arrfilename [arrfilename. Count - 1 ]. Tostring ();

// Obtain the path to save the file. The front is the physical path on the server where the current page is located.
String Uploadpath = Page. Request. physicalapplicationpath +   " Uploadfiles \\ " ;

// Upload a file.
File1.postedfile. saveas (uploadpath + Filename );
Page. response. Write ( " File Uploaded successfully! " );
}

OK! Please try again later!

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.