.netsharepointhttpwebrequestwebrequest

Reasons for a 409/Conflict HTTP error when uploading a file to sharepoint using a .NET WebRequest?


I've got a method that uses a WebRequest to upload a file to a sharepoint 2010 list/folder, using a PUT request, with the Overwrite Header set to T (overwrite).

When several files are uploaded (method is called several times), some requests fail with a 409 Conflict HTTP error.

I've googled, and it seems the most common reason is trying to affect/update a file that does not exist (like setting the request URL to a path without a file name). However, that is not the case. In case the conflict had something to do with the file already existing, I added code to physically delete the file before uploading it, and i'm still getting some 409's.

Has anyone received this type of error, and if so, can you tell me how you fixed it and what was the root cause?


Solution

  • I found the following here:

    The Web server (running the Web site) thinks that the request submitted by the client (e.g. your Web browser or our CheckUpDown robot) can not be completed because it conflicts with some rule already established. For example, you may get a 409 error if you try to upload a file to the Web server which is older than the one already there - resulting in a version control conflict.

    Someone on a similar question right here on stackoverflow, said the answer was:

    I've had this issue when I was referencing the url of the document library and not the destination file itself.

    i.e. try http://server name/document library name/new file name.doc

    However I am 100% sure this was not my case, since I checked the WebRequest's URI property several times and the URI was complete with filename, and all the folders in the path existed on the sharepoint site.