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!