2

I'm working on a Winform application which allows a user to upload documents to Onedrive for Business. Essentially you select a folder you want to upload, this creates all of the folders and then uploads the documents.

This ignores files with illegal extensions and renames any folders and files that contain illegal characters.

It seems to work ok but I get a 400 Bad Request, so I looked in to the length of the url. This appears to be fall with in the 260 limit unless I'm missing something? Items that fail are greater then 205 characters.

Is the following article still applicable to Sharepoint online: http://blogs.msdn.com/b/selvagan/archive/2009/12/06/unable-to-edit-files-uploaded-to-document-library-where-url-length-is-more-than-260-characters.aspx

Also is there any way I can get any detail information about a 400 Bad Request?

Is there any where on Microsoft that documents this for SharePoint Online, I've come across 2010 but nothing for SharePoint Online.

This is an example of an item that failed https://sitename-my.sharepoint.com/personal/sitename_sitename_onmicrosoft_com/Documents/SharePoint 2013 Using the search REST service from an app for SharePoint/C_/SharePoint_2013_Using_the_search_REST_service_from_an_app_for_SharePoint.docx

After adding some more error handling I now get the following message:

The length of the URL for this request exceeds the configured maxUrlLength value.

1
  • Webfort could you please describe what do you mean under: > I've changed my code to create the folders using Json Could you help find it in documentation, please? I cant find anything like that on this page
    – YAD
    Oct 21, 2015 at 17:29

2 Answers 2

6

There is a maximum 256 character limit in SharePoint for REST URLs - reference:

https://msdn.microsoft.com/en-us/LIbrary/dn292556.aspx

However URL parameters are not included in the length-restriction, so can be used to get round this limit. Here is an example of using URL parameters to bypass this limit:

https://tenant-my.sharepoint.com/personal/user_account_tenant_onmicrosoft_com/_api/web/getfilebyserverrelativeurl(@v)/startupload(uploadId=guid'38acfb37-ccd5-4ac1-961d-090ce1ed9d6f')?@v='/personal/user_account_tenant_onmicrosoft_com/Documents/Test/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso.001'

For a little more information you can see this post:

The length of the URL for this request exceeds the configured maxUrlLength value. REST API

0
2

I was using the following code to add a file to a folder

url: http://site url/_api/web/GetFolderByServerRelativeUrl('/FolderName')/Files/add(url='a.txt',overwrite=true)
method: POST
body: "Contents of file"
Headers: 
Authorization: "Bearer " + accessToken
X-RequestDigest: form digest value
content-length:length of post body

if you have a quite a deep folder structure or folders with large names you'll hit the limit and get "The length of the URL for this request exceeds the configured maxUrlLength value."

I've changed my code to create the folders using Json and posting this data. Also when I create my folders I get the uniqueid for the folder and then use getfolderbyid to upload my file.

1
  • are you sending the URL inside the body? if yes, how so? Oct 28, 2015 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.