写的asp.net网页 用的WebClient实现下载图片功能,在本机上运行正常 下载也可以(图片存放的服务器地址是41的),但是把代码放到服务器(服务器地址是58)上做网站 再在本机打开网页运行ok,但是下载图片就出现 “设备未就绪” 错误
System.Net.WebException: An exception occurred during a WebClient request. ---> System.IO.IOException: 设备未就绪。 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at System.Net.WebClient.DownloadFile(Uri address, String fileName) --- End of inner exception stack trace --- at System.Net.WebClient.DownloadFile(Uri address, String fileName) at System.Net.WebClient.DownloadFile(String address, String fileName) at KANBAN.SourcesReport.Button7_Click(Object sender, EventArgs e) in c:\Users\Administrator\Desktop\SPC\KANBAN\KANBAN\SourcesReport.aspx.cs:line 859
代码是:
try
{
if (TextBox5.Text != null && !TextBox5.Text.Equals(""))
{
string[] tu = TextBox5.Text.Split('/');
WebClient my = new WebClient();
foreach (string s in tu)
{
my.Credentials = CredentialCache.DefaultCredentials;
my.Headers.Add(HttpRequestHeader.UserAgent, "anything");
my.DownloadFile(@"\\10.132.118.41\\开发专用\\Images\chengshi\\" + s, "D:\\" + s);
ClientScript.RegisterStartupScript(this.GetType(), "227", "alert('圖片下載完成!存在D盤');", true);
}
//如果是真实的图片地址直接用
}
else
ClientScript.RegisterStartupScript(this.GetType(), "2217", "alert('不存在图片');", true);
}
catch (Exception ex)
{
qq.Text = ex.ToString();
}
------解决思路----------------------
my.DownloadFile(@"\\10.132.118.41\\开发专用\\Images\chengshi\\" + s, "D:\\" + s);
你确定服务器(服务器地址是58)上有D盘,并且网站程序有权限访问吗?
------解决思路----------------------
download地址有问题,不要有绝对路径
------解决思路----------------------
my.DownloadFile(@"\\10.132.118.41\\开发专用\\Images\chengshi\\" + s, "D:\\" + s);中\\是本地路径,如果你是要下载网站服务器上的,应该加上是http://,另外反斜杠(\)也应该改成斜杠(/)