Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour when using CSOM to create DocumentSets with names containing "#" or "%" #9458

Open
1 of 9 tasks
ltdu opened this issue Jan 14, 2024 · 1 comment
Open
1 of 9 tasks
Labels
area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.

Comments

@ltdu
Copy link

ltdu commented Jan 14, 2024

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

SharePoint CSOM

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

Microsoft.SharePointOnline.CSOM: 16.1.24322.12000

Describe the bug / error

Special characters # and % are supported in paths and file/folder names for some time:

Supporting % and # in files and folders with the ResourcePath API

While this page does not mention Document Sets, you can use standard SharePoint UI to create new document set containing both of these characters:

image

However, if you try to create new document set using CSOM, results are inconsistent:

  • If # is used, error message "File Not Found." is returned
  • if % is used which is followed by some numeric value, it will be URL-decoded into another character
  • if % is used and it cannot be URL-decoded, document set is created with correct name

Steps to reproduce

  1. Enable Document Sets feature
  2. Create standard document library
  3. Add Document Set content type to it
  4. Use CSOM code to create new document sets:
using var clientContext = new ClientContext("https://___.sharepoint.com/sites/demo-docset-issue");
clientContext.ExecutingWebRequest += await AttachAuthorization();

var listUrl = "/sites/demo-docset-issue/docs";
var ctypeId = "0x0120D52000639392D323B55A4FAC637C3B25FA070D";

var web = clientContext.Web;
var list = web.GetList(listUrl);
var ctype = list.ContentTypes.GetById(ctypeId);
var folder = list.RootFolder;

clientContext.Load(folder);
clientContext.Load(ctype);
await clientContext.ExecuteQueryAsync();

// Following throws exception with message "File Not Found."

try
{
    var docSetName1 = "Test # 123";
    var docSetUrl1 = DocumentSet.Create(clientContext, folder, docSetName1, ctype.Id);
    await clientContext.ExecuteQueryAsync();
    Console.WriteLine(docSetUrl1.Value);
}
catch (Exception ex1)
{
    Console.WriteLine(ex1.Message);
}

// This one create document set with different name and returns
// https://___.sharepoint.com/sites/demo-docset-issue/docs/Test 3

try
{
    var docSetName2 = "Test %123";
    var docSetUrl2 = DocumentSet.Create(clientContext, folder, docSetName2, ctype.Id);
    await clientContext.ExecuteQueryAsync();
    Console.WriteLine(docSetUrl2.Value);
}
catch (Exception ex2)
{
    Console.WriteLine(ex2.Message);
}

// Document set with correct name is created:
// https://___.sharepoint.com/sites/demo-docset-issue/docs/Test % 123

try
{
    var docSetName3 = "Test % 123";
    var docSetUrl3 = DocumentSet.Create(clientContext, folder, docSetName3, ctype.Id);
    await clientContext.ExecuteQueryAsync();
    Console.WriteLine(docSetUrl3.Value);
}
catch (Exception ex3)
{
    Console.WriteLine(ex3.Message);
}

Expected behavior

It is expected for CSOM to work correctly and create document sets with provided names.

Additional note 1: it seems JSOM partially works with # - error message is not return, however name is changed so that only part of provided value remains (Test 1#23 becomes Test 1).

Additional note 2: while standard UI is able to create document set with #, most likely it creates folder without it and renames afterwards; and if that folder already exists - it throws an error:

image

@ltdu ltdu added the type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. label Jan 14, 2024
@ghost
Copy link

ghost commented Jan 14, 2024

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 Awaiting categorization and initial review. label Jan 14, 2024
@VesaJuvonen VesaJuvonen added area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API and removed Needs: Triage 🔍 Awaiting categorization and initial review. labels Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs.
Projects
None yet
Development

No branches or pull requests

2 participants