Asked by:
SharePoint Create Folder fails randomly with CSOM

Question
-
I have implemented an upload process for SharePoint with C# in Azure Functions and CSOM. The upload process will also create folders in SharePoint recursive.
The following error will be thrown after some folders are created:
{"parameters.Content, parameters.ContentStream\r\nParameter name: The specified value is not supported for the parameters.Content, parameters.ContentStream parameter"}.
Code (dest is the destination context):
Folder _folder = dest.Web.GetFolderByServerRelativeUrl(folder.ServerRelativeUrl);
_folder.Folders.AddWithOverwrite(folder.ServerRelativeUrl+"/"+item.Property.Name,true);
dest.Load(_folder);
dest.ExecuteQuery();
All replies
-
-
-
If you create a new folder and upload file into another SharePoint online document library does you and your teammate meet the same behavior, it will help for us to narrow down your issue.
May I know have you tried another bowser like “Microsoft edge” does it make any difference, please verify the result with us.
In the meantime, if there is no issue with your SharePoint online document library, you may try another way to create a new folder and upload file on your SharePoint library to meet your requirement.
Please try to sync your affected SharePoint online document library to local machine using OneDrive client app and then try to create a new folder or upload file in sync document library then go to SharePoint library via bowser to check the outcomes.This may help you,
Rachel Gomez
-
The error message indicates that the value provided for the parameters.Content or parameters.ContentStream parameter is not supported. However, based on the code snippet provided, it does not seem to be related to the upload process or the creation of folders.
The error could be caused by an invalid value being passed to the parameters.Content or parameters.ContentStream parameter in another part of your code. It is recommended to review the code and ensure that all parameters are properly validated and that the correct data types are being passed.
Another possibility is that the error is related to the destination context. It is recommended to check that the destination context is properly initialized and that the correct SharePoint site URL is being used.
Finally, it is recommended to add error handling to your code to provide more detailed error messages and to handle exceptions gracefully. This will make it easier to troubleshoot issues like this in the future.
- Proposed as answer by DotNetDeveloper95 Thursday, February 23, 2023 1:45 PM
-
I was just making an account at https://bc.game/id when I saw your answer. Anyway, thank you for your helpful response! I will review my code too and ensure that the content is properly formatted to resolve the issue with what you said.
- Edited by Juljit Chumchai Wednesday, March 8, 2023 3:24 AM message got doubled
-
The error message you are receiving indicates that the value you are passing to the
parameters.Content
orparameters.ContentStream
parameter is not supported.In your code, it appears that you are trying to create a new folder in SharePoint using the
AddWithOverwrite
method, passing thefolder.ServerRelativeUrl
anditem.Property.Name
parameters. It's possible that one of these parameters is causing the issue.To troubleshoot this error, you can try the following steps:
-
Check the values of
folder.ServerRelativeUrl
anditem.Property.Name
to ensure that they are valid SharePoint URLs. -
Verify that the
dest
object is initialized correctly and has the necessary permissions to create folders in SharePoint. -
Try uploading a file to the same folder using the
UploadFile
method to see if you receive a similar error. This will help you isolate whether the issue is specific to theAddWithOverwrite
method or a more general issue with uploading content to SharePoint. -
Try using a different method to create the folder, such as
dest.Web.Folders.Add(folder.ServerRelativeUrl + "/" + item.Property.Name)
to see if you receive a different error message.
If none of these steps resolve the issue, it may be helpful to consult the SharePoint documentation or seek assistance from Microsoft support to troubleshoot the issue further.
-
-