Remove Invalid Characters With RegEx – C#

We integrated CRM with SharePoint and decided to create a document set for every entity in CRM. I wrote an application to automate the process using C# and ran into an issue with entity names ending with periods (e.g. Company Name, Inc.).

During the create action I replace invalid characters using this RegEx:

@"[\*\?\|\\\t/:""'<>#{}%~&]|[\. ]$"

It looks like this:

DocumentSet docSet = DocumentSet.Create(parentFolder, Regex.Replace(DocumentSetName.Trim(), @"[\*\?\|\\\t/:""'<>#{}%~&]|[\. ]$", ""), docsetCT.Id, properties, true);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s