今天要在网站上面做一个批量上传的工具,但是不想用控件上传,感觉好麻烦,所以就在网上找了些资料,后来发现这种功能是可以实现下面我贴出代码:
这个是在aspx.cs页面的代码:
1
protected void Button1_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("您所要上传的文件夹是:" + path + "<br />");9

10
string[] pics = Directory.GetFiles(path);11
foreach (string a in pics)12

{13
try14

{15
UpLoad(a);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
}
这个代码在本地是可以实现的,但是我编译后放在服务器上就不能用了,
说明一下:我是根据上传空间选中的文件来判断文件夹的,然后上传这个文件夹中的所有图片,本地一点问题也没有,到服务器上就会报如下错误
错误为:
Server Error in '/' Application.
Could 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: Could 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. |
这个错误蛮奇怪的,如果是服务器的权限,到没什么,但是确实我本地的文件夹,不需要的呀!
有没人做过类似的东西,请教一下!
转载于:https://www.cnblogs.com/Longkin/archive/2008/09/19/1294043.html