Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Gentleman; I am trying to upload a file to folder on my website "User Images". I am using the following code:
C#
WebClient myWebClient = new WebClient();
           string fileName = theFile.Text;
           string Uri = "My Website/User_Images";
           byte[] responseArray = myWebClient.UploadFile(Uri, fileName);


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
Posted
Comments
Sergey Alexandrovich Kryukov 18-Nov-15 17:03pm    
Whats make you believe that your "Uri" represents some URI? Where is the real URI needed for HTTP request? (Do you mean it's there, but you've shortened it down for secrecy?) And, finally, what makes you believe that the site really handles file uploads?
—SA
PDTUM 18-Nov-15 17:21pm    
Hello Sergey. Thank you for your response. Well, yes, there was a real URL in there or I would not have gotten a server response, so to clarify, let me try this again:

string Url = "http://MyWebPage.com/User_Images";

As to the second question, the answer is "I Don't Know". I thought that the code would need to include some kind of "login" so that the upload could be authenticated, but that was just a guess on my part. None of the MSFT samples I read showed one. I am a application programmer and I avoid web stuff except when necessary to interface it for some reason or other. I thought that perhaps the web client might have an overload that accepts arguments to pass along, but that is not the case. So, I 'assume ' that there must be a line or two of code to make that happen from within the statement? Again, I am asking, not suggesting. Can you help me along? Thank you.
Sergey Alexandrovich Kryukov 18-Nov-15 17:35pm    
I hardly can help because I know about this site even less than you. But I'll tell you one thing: I don't accept work which should be done in blind-folded way, and don't advise anyone to do so.
—SA

1 solution

Have you tried to set the credentials?

WebClient.Credentials Property[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900