AI OnAI Off
and when you enter EPiServer edit mode you see the SE, DK, NO and EN Flags.
//
Jörgen
protected void Application_Start(Object sender, EventArgs e)
{
EPiServer.Global.EPDataFactory.FinishedLoadingPage += new PageEventHandler(hideNonSupportedLanguageTabs);
EPiServer.Global.EPDataFactory.LoadedDefaultPageData += new PageEventHandler(hideNonSupportedLanguageTabs);
}
///
/// Hides langauge tabs on multilanguage (edit mode) pages that is not supported by the current site.
///
/// The invoking object
/// Parameters, e.g. the page
private static void hideNonSupportedLanguageTabs(object sender, PageEventArgs e)
{
string siteSupportedLanguages;
try
{
siteSupportedLanguages = EPiServer.Global.EPConfig["EPsLanguageSortOrder"].ToString();
for(int i = e.Page.Property.Count - 1 ; i >= 0 ; i-- )
{
PropertyData prop = e.Page.Property[i];
if (isSupportedLanguage(prop.Name, siteSupportedLanguages))
{
continue; // To next iteration
}
// Remove the property and replace it with itself after the name and tab i changed
e.Page.Property.Remove(prop.Name);
String newPropertyName = prop.Name.Replace("___", "__");
prop.OwnerTab = -1; prop.Name = newPropertyName;
e.Page.Property.Add(newPropertyName, prop);
}
}
catch(Exception ex)
{
}
}
///
/// Checks if property belongs to the supported languages of the site.
///
/// The property name to test if it specifying a supported language
/// A comma-separated list of languages, each language described in two-letter abbreviation
/// True if the property has a postfix indicating that it belongs to one of the languages in the list of supported
/// languages or if the property is not language dependant, false otherwise.
private static bool isSupportedLanguage(string property, string supportedLanguages)
{
string languages = supportedLanguages.Replace(" ","")+ ",";
int separatorIndex = property.IndexOf(MultiLanguageRuntime.LANGUAGEPROPERTYSEPARATOR);
//Check if property is multilanguage compatible
if (separatorIndex >= 0)
{
string propLang = property.Substring(separatorIndex+MultiLanguageRuntime.LANGUAGEPROPERTYSEPARATOR.Length, 2);
if (languages.IndexOf(propLang + ",") >= 0)
{
return true;
}
}
else
{
//Property is not multilanguage, so should always be included
return true;
}
return false;
}
protected static NameValueCollection FindInstanceSettings(string project)
{
configEnum.Reset();
while(configEnum.MoveNext())
{
if(configEnum.Value.GetType().ToString() == "System.Collections.Specialized.NameValueCollection")
{
System.Collections.Specialized.NameValueCollection instance = configEnum.Value as System.Collections.Specialized.NameValueCollection;
if(Code.Common.GetString(instance["EPsProjectCode"]).ToUpper() == project)
{
return instance;
}
}
}
return null;
}
This method returns a NameValueCollection:
public void SomeMethod()
{
NameValueCollection instance = new NameValueCollection();
instance = FindInstanceSettings("Site1");
}
Frank :)
protected static Hashtable configurations;
protected static IDictionaryEnumerator configEnum;