ASP. NET makes uploading files from the client to the server a snap (uploadinterface. postedfile. saveas

Source: Internet
Author: User
Http://www.computerbooksonline.com/tips/asp11.asp
In a previous tip, we talked about uploading files via classic ASP. as you saw, getting the file from the client to the server isn't a big deal, but getting ASP to handle the file properly, once delivered, was no walk in the park. fortunately, like most other tasks that were once tedious or impossible in ASP, Asp. net makes this task simple.

All you have to do is provide the interface for the upload, in the same way you wowould do with ASP --Tag corresponds in ASP. net to a server-side system. web. UI. htmlcontrols. htmlinputfile control, which is rendered in HTML in exactly the same way. then, in your code-behind page, use something like the following intuitive code:

Protected sub uploadbutton_onclick (byval sender as object, byval e
System. eventargs) handles uploadbutton. Click
Dim fileupload as httppostedfile
Dim uploadedfilename as string

'Get the file from the htmlinputfile Control
Fileupload = uploadinterface. postedfile

If not uploadinterface. postedfile is nothing then
'Get just the filename (without the client path)
Uploadedfilename =
Fileupload. filename. substring (fileupload. filename. lastindexof ("\"))
'Save it in a safe place on the server
Uploadinterface. postedfile. saveas ("C: \ temp \" & uploadedfilename)
End if
End sub

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.