AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    Kentico development modelsInstallationUsing the Kentico interfaceDeveloping websitesConfiguring KenticoManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresCommunity featuresRelease notes - Kentico 12
  • Tutorial
    Getting started with KenticoUsing the Kentico interfaceSelecting your tutorial pathSite development overviewPortal Engine developmentMVC developmentMVC business tutorialResource hub for marketers
  • API Examples
    Content managementOn-line marketingE-commerceSocial and CommunityDevelopmentConfiguration

Is this really the version you are looking for? Kentico Xperience 12 Service Pack API is no longer updated. Use the switcher in the header to choose your product version.

  1. Home
  2. Social and Community
  3. Bad words

Bad words


Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Creating a bad word
  • Updating a bad word
  • Updating multiple bad words
  • Checking text for a bad word
  • Checking text for all bad words defined in the system
  • Deleting a bad word

Creating a bad word

C#
// Creates a new bad word object
BadWordInfo newWord = new BadWordInfo();

// Sets the bad word properties
newWord.WordExpression = "testbadword";
newWord.WordAction = BadWordActionEnum.ReportAbuse;
newWord.WordIsGlobal = true;
newWord.WordIsRegularExpression = false;

// Saves the bad word to the database
BadWordInfoProvider.SetBadWordInfo(newWord);
> Back to list of examples

Updating a bad word

C#
// Gets the specific bad word
var words = BadWordInfoProvider.GetBadWords().WhereEquals("WordExpression", "testbadword");
BadWordInfo word = words.FirstOrDefault();

if (word != null)
{
    // Updates the bad word properties
    word.WordAction = BadWordActionEnum.Replace;
    word.WordReplacement = "good";

    // Saves the changes to the database
    BadWordInfoProvider.SetBadWordInfo(word);
}
> Back to list of examples

Updating multiple bad words

C#
// Gets the bad words containing the word 'bad'
var words = BadWordInfoProvider.GetBadWords().WhereContains("WordExpression", "bad");

// Loops through individual bad words
foreach (BadWordInfo word in words)
{
    // Updates the properties
    word.WordAction = BadWordActionEnum.Replace;
    word.WordReplacement = "good";

    // Saves the updated bad word
    BadWordInfoProvider.SetBadWordInfo(word);
}
> Back to list of examples

Checking text for a bad word

C#
// Gets the specific bad word
var words = BadWordInfoProvider.GetBadWords().WhereEquals("WordExpression", "testbadword");

if (words.Count > 0)
{
    // Gets the object representing the bad word from the collection of results
    BadWordInfo badWord = words.FirstOrDefault();

    // Creates a string to be checked for the presence of the bad word
    string text = "This is a string containing the sample testbadword";

    // Creates a hashtable that will contain found bad words
    Hashtable foundWords = new Hashtable();

    // Modifies the string according to the found bad words and returns the action which should be performed
    BadWordActionEnum action = BadWordInfoProvider.CheckBadWord(badWord, null, null, ref text, foundWords, 0);

    if (foundWords.Count != 0)
    {
        switch (action)
        {
            case BadWordActionEnum.Deny:
                // Perform additional actions here
                break;

            case BadWordActionEnum.RequestModeration:
                // Perform additional actions here
                break;

            case BadWordActionEnum.Remove:
                // Perform additional actions here
                break;

            case BadWordActionEnum.Replace:
                // Perform additional actions here
                break;

            case BadWordActionEnum.ReportAbuse:
                // Perform additional actions here
                break;

            case BadWordActionEnum.None:
                // Perform additional actions here
                break;
        }
    }
    else
    {
        // The bad word is not present in the checked string
    }
}
> Back to list of examples

Checking text for all bad words defined in the system

C#
// Creates a string to be checked for the presence of bad words
string text = "This is a string containing the sample testbadword.";

// Creates a hashtable that will contain found bad words
Hashtable foundWords = new Hashtable();

// Modifies the string according to the found bad words and returns the action which should be performed
BadWordActionEnum action = BadWordInfoProvider.CheckAllBadWords(null, null, ref text, foundWords);

if (foundWords.Count != 0)
{
    switch (action)
    {
        case BadWordActionEnum.Deny:
            // Perform additional actions here
            break;

        case BadWordActionEnum.RequestModeration:
            // Perform additional actions here
            break;

        case BadWordActionEnum.Remove:
            // Perform additional actions here
            break;

        case BadWordActionEnum.Replace:
            // Perform additional actions here
            break;

        case BadWordActionEnum.ReportAbuse:
            // Perform additional actions here
            break;

        case BadWordActionEnum.None:
            // Perform additional actions here
            break;
    }
}
else
{
    // The bad words are not present in the checked string
}
> Back to list of examples

Deleting a bad word

C#
// Gets the specific bad word
var words = BadWordInfoProvider.GetBadWords().WhereEquals("WordExpression", "testbadword");
BadWordInfo word = words.FirstOrDefault();

if (word != null)
{
    // Deletes the bad word
    BadWordInfoProvider.DeleteBadWordInfo(word);
}
> Back to list of examples