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:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s