2

I am using the SharePoint Online CSOM library (16.1.8316.1200) to retrieve info about a SharePoint Online folder using the web.GetFolderByServerRelativeUrl. This works great except for when the folder contains a "#" character. In that case, a ServerException 'File Not Found' is returned. I have tried encoding the "#" character as "%23" but that did not work either. Any ideas of what I can do?

2

You can get a folder name containing special characters such as # and % using the new GetFolderByServerRelativePath method.

You can use the below snippet:

string folderName = "Test#123";

var folder = clientContext.Web.GetFolderByServerRelativePath(ResourcePath.FromDecodedUrl($"/sites/TestSite/Documents{folderName}"));
clientContext.Load(folder);
clientContext.ExecuteQuery();

Console.Write(folder.Name);

Reference - Web.GetFolderByServerRelativePath method

1

Reproduced, here is my test workaround.

var folders = context.Web.GetFolderByServerRelativeUrl("/sites/Developer/MyDoc4/SubFolder").Folders;                
                context.Load(folders, fs => fs.Where(f => f.ServerRelativeUrl == "/sites/Developer/MyDoc4/SubFolder/T#T")); ;
                context.ExecuteQuery();
                foreach (var _F in folders)
                {
                    Console.WriteLine(_F.Name);
                }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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