将文件从C#桌面应用程序上传到网站文件夹

问题描述:

君子;我正在尝试将文件上传到我的网站用户图像上的文件夹。我使用以下代码:

Gentleman; I am trying to upload a file to folder on my website "User Images". I am using the following code:

WebClient myWebClient = new WebClient();
           string fileName = theFile.Text;
           string Uri = "My Website/User_Images";
           byte[] responseArray = myWebClient.UploadFile(Uri, fileName);





它返回以下错误:

{远程服务器返回错误:(405)方法不允许。}



我认为有可能存在某种类型的登录以获得上传许可,但是我在这里和一般都做了一些搜索,我找不到我要找的东西。有人能为我提供一个代码示例,我可以用它来解决这个看似简单的问题吗?谢谢您的帮助。 Pat



It is returning the following error:
{"The remote server returned an error: (405) Method Not Allowed."}

I suppose it makes sense that there might be some type of "log in" for permission to do the upload, but I have done some searches both here and in general and I cannot find what I am looking for. Can someone supply me with a code example that I can use to resolve this seeming simple problem? Thank you for your help. Pat

您是否尝试过设置凭据?



WebClient.Credentials Property [ ^ ]
Have you tried to set the credentials?

WebClient.Credentials Property[^]