webclient.uploadfile无法正常工作 [英] webclient.uploadfile not working

查看:72
本文介绍了webclient.uploadfile无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将文件上传到asp.net 1.1 winforms应用程序中的远程服务器。我正在使用System.Net.WebClient方法上传文件。


但是,运行时出现以下错误:


" System.IO.IOException :文件名,目录名称或卷标语法不正确。\\\\\ n  在System.IO .__ Error.WinIOError(Int32 errorCode,String str)\\\\ n  在System.IO.FileStream..ctor(String path,FileMode mode,
FileAccess access,FileShare share,Int32 bufferSize,Boolean useAsync,String msgPath,Boolean bFromProxy)\\ nn; 在System.IO.FileStream..ctor(String path,FileMode mode,FileAccess access,FileShare share)\\ nn;在System.Net.FileWebStream..ctor(FileWebRequest
请求,字符串路径,FileMode模式,FileAccess访问,FileShare共享)\\ n  在System.Net.FileWebRequest.InternalGetRequestStream()"


这是我上传文件的代码:           

 

System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredential(uName,pwd);
try
{
Byte [] response = wc.UploadFile(@" \\ServerIP\C $ \Attachments\","POST",txt_filename。文本);
}
catch(Exception ex)
{
exc = ex.InnerException.ToString();
}

请告诉我这里出了什么问题。

谢谢

Abhi


Abhi

解决方案


txt_filename.Text < /跨度>

Hi,

I'm trying to upload files to a remote server in asp.net 1.1 winforms application. I'm using the System.Net.WebClient method to upload the file.

However, I'm getting the following error when I run it:

"System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.\r\n\r\n   at System.IO.__Error.WinIOError(Int32 errorCode, String str)\r\n   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)\r\n   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)\r\n   at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing)\r\n   at System.Net.FileWebRequest.InternalGetRequestStream()"

Here's my code to upload the files:           

System.Net.WebClient wc = new System.Net.WebClient(); wc.Credentials = new System.Net.NetworkCredential(uName,pwd); try { Byte[] response = wc.UploadFile(@"\\ServerIP\C$\Attachments\","POST",txt_filename.Text); } catch(Exception ex) { exc = ex.InnerException.ToString(); }

Please let me know what am doing wrong here.

Thank you

Abhi


Abhi

解决方案

What is the value of txt_filename.Text?


这篇关于webclient.uploadfile无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆