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

Viewed 194991

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? Any help is greatly appreciated. Thanks

10 Answers

At times the error code 409 occurs when you name you folder or files a reserved or blocked name. These could be names like register, contact

In my case I named a folder contact, turns out the name was blocked from being used as folder names.

When testing my script on postman, I was getting this error:

<script>
    document.cookie = "humans_21909=1"; document.location.reload(true)
</script>

I changed the folder name from contact to contacts and it worked. The error was gone.

Its because of wrong path provided. It may be that the url contains space and if the case url has to be properly constructed.

The correct url should be in the format with file name included like "http://server name/document library name/new file name"

So if report.xlsx is the file that has to be uploaded at "http://server name/Team/Dev Team" then path comes out to be is "http://server name/Team/Dev Team/report.xlsx". It contains space so it should be reconstructed as "http://server name/Team/Dev%20Team/report.xlsx" and should be used.

I ran into this issue several times for different reasons. I'll list some of them here.

  1. The Chrome browser is caching the request. You can disable this in the chrome developer console or in the code use the header {cache: 'no-cache'}

  2. The nested folder path does not exist when putting the file. Make sure the folder exists first, before putting the file into the nested folder.

  3. Both the new file and the old file content are (about) the same, as well as the commit message. Just change the commit message to be more randomised. Use something like this in the commit message.

     const date = new Date()
     const timeStampHash = `${date.toISOString()}-${Math.floor(Math.random() * 1000)}`
     const commitMsg = `Commited from my App: #${timestampHash}`
     

I is because you are using predefined variables to naming your filename. change your filename from e.g register.asp to registerUser.asp. That will solve your issue

please rename your file or folder name of API like- xyz.com/register.php rename it xyz.com/myregister.php

some name, keyword is blocked on getting this error

Related