Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have custom control which displays different details depending on which site the user is currently at. My problem is that as soon as the URL contains non-alphabetic characters, the controls fails to show any details at all.

Works: http://myserver/subsiteone

Doesn't work: http://myserver/subsite%20two

Snippet of my code

private enum Investor { None, Ventures, Growth, Seeds }
protected override void OnInit(EventArgs e)
{
    var investor = CheckUrl(SPContext.Current.Site.OpenWeb().Url);

    switch (investor)
    {
        case Investor.None:
            Controls.Add("Some data");
            break;
        case Investor.Ventures:
            Controls.Add("Some data");
            break;
        case Investor.Growth:
            Controls.Add("Some data");
            break;
        case Investor.Seeds:
            Controls.Add("Some data");
            break;
    }
}

private static Investor CheckUrl(string url)
{
    return url.Contains("Ventures") ? Investor.Ventures : (url.Contains("Growth%20Samples") ? Investor.Growth : (url.Contains("Seeds") ? Investor.Seeds : Investor.None));
}

As you can see, when I check on Investor.Growth the URL should contain Growth%20Samples, and it does but the code somehow doesn't approve of it as valid and skips on.

How can I prevent this from happening, since it approves the other parameters which have nothing but alphabetic characters in them?

EDIT: This is continuous development on an existing site with tons of subsites, lists etc so a recreation of the site is not possible at this point.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Found solution to this.

const string growth = "Growth Sample";
var xEncode = SPHttpUtility.HtmlEncode(growth); 
url.Contains(xEncode) // Taken out of context

I don't know why url.Contains("Growth%20Samples") didn't work, as SPHttpUtility.HtmlEncode gives the exact same output.

Anyhow, enjoy!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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