An error occurred while using WebClient to upload files without space: cocould not find a part of the path .....

Source: Internet
Author: User
Tags stack trace

Today, I want to create a bulk upload tool on the website, but I don't want to use controls to upload it, which is very troublesome. So I found some information on the Internet. Later, I found that this function can be implemented below.Code:

This is the code on the Aspx. CS page:

 

Code
1 Protected   Void Button#click ( Object Sender, eventargs E)
2 {
3 If (Fileupload1.hasfile)
4 {
5 String Temp = Fileupload1.postedfile. filename;
6 String Path = Temp. substring ( 0 , Temp. lastindexof ( ' \\ ' ));
7
8 Response. Write ( " The folder you want to upload is: "   + Path +   " <Br/> " );
9
10 String [] Pics = Directory. getfiles (PATH );
11 Foreach ( String A In PICS)
12 {
13 Try
14 {
15Upload ();
16}
17 Catch   {}
18 }
19 }
20 }
21
22 Private   Bool Upload ( String Filename)
23 {
24 WebClient WC =   New WebClient ();
25 Byte [] Responsearry = WC. uploadfile (common. siteurl +   " /Tools/product/upload. aspx " , " Post " , Filename );
26 Label1.text = System. Text. encoding. ASCII. getstring (responsearry );
27 Return   True ;
28 }

 

This code can be implemented locally, but it cannot be used after being compiled on the server,

Note: I used to determine the folder Based on the selected file in the upload space, and then uploaded all the images in the folder. There is no local problem at all. The following error will be reported on the server:

Error:

 

Server Error in '/'application.

Cocould not find a part of the path 'e: \ 1233566 \ at005611.jpg '.

Description: An unhandled exception occurred during the execution of the current Web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception details: system. Io. directorynotfoundexception: cocould not find a part of the path 'e: \ 1233566 \ at005611.jpg '.

Source error:

An unhandled exception was generated during the execution of the current Web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

 

 

This error is quite strange. If it is the server permission, there is nothing, but my local Folder does not need it!

 

Nobody has done something similar. Please ask!

 

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.