I have this code, but I get the error described in the title:
“The remote server returned an error: (405) Method Not Allowed.”
** I’ve replaced PUT by POST now**
If I replace “PUT” by “POST” it seems to work as I don’t get an error, but it does not upload any file.
I’m trying to upload a file to a document library in sharepoint (office 365)
public static void UploadTest()
{
WebClient w = new WebClient();
w.Credentials = new NetworkCredential("username", "password");
var ua = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
w.Headers["Accept"] = "/";
w.Headers.Add(HttpRequestHeader.UserAgent, ua);
byte[] bFile = System.IO.File.ReadAllBytes(@"C:\t.txt");
string ulr = @"http://www.website.com/uploadfolder/";
System.Uri oUri = new System.Uri(ulr);
try
{
w.UploadData(oUri, "POST", bFile);
w.UploadDataCompleted += new UploadDataCompletedEventHandler(oWebClient_UploadDataCompleted);
Console.WriteLine("Uri:" + oUri);
}
catch (Exception ex)
{
throw ex;
}
finally
{
Console.ReadLine();
}
}
There is a problem regarding access with credentials and logging in.
Something seems to go wrong when I try to connect, as I can download a corrupt file when I remove the w.Credentials = new NetworkCredential(user,pass);
I’m trying a total new way around now, thanks for replying.