Asp vb. NET client uploads files to the server

Source: Internet
Author: User

Dim strpath as string = server. mappath ("~ /Folder ")
'Create if the path of the saved file does not exist
If not directory. exists (strpath) then
Directory. createdirectory (strpath)
End if
Dim path as string = server. mappath (fileupload1.filename ))
'Upload if the file exists.
If (fileupload1.hasfile) then
Fileupload1.postedfile. saveas (PATH)
End if
'A: import the Excel file to dateview first.
'2: import the data in dateview to the database.
'Excel connection string
Dim sconnectionstring as string = "provider = Microsoft. Jet. oledb.4.0 ;"&_
"Data Source =" + path + ";"&_
"Extended properties = Excel 8.0 ;"
'Establish an Excel connection
Dim objconn as new oledbconnection (sconnectionstring)
Objconn. open ()
Dim objcmdselect as oledbcommand = new oledbcommand ("select * from [sheet1 $]", objconn)
Dim objadapter as oledbdataadapter = new oledbdataadapter ()
Objadapter. selectcommand = objcmdselect
Dim objdataset as dataset = new dataset ()

Objadapter. Fill (objdataset, "xldata ")
Dim dT as datatable = objdataset. Tables (0)

'After the table is converted, the operation can be performed immediately.

 

It is worth noting that you must have the permission to upload files. Therefore, add a line of code under the <Authentication mode = "Windows"/> node in Web. config.

<Identity impersonate = "true" username = "Domain Name/account" Password = "*****"/>

 

When publishing a website, you must add this sentence to the server. Otherwise, an error will be reported.

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.