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.