SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to build a custom filter provider that can detect the user language (the language selected in SharePoint by the user) and provide it as a filter.

As a language can be represented in many ways (ex: French can be written "fr", "fre", "fra", "français", "french", "1036"), I want to push multiple values in my web part.

By now, I have written this code :

[ToolboxItemAttribute(false)]
public class LanguageFilterProviderWebPart : WebPart, ITransformableFilterValues
{
    public virtual bool AllowAllValue
    {
        get { return true; }
    }

    public virtual bool AllowEmptyValue
    {
        get { return false; }
    }

    public virtual bool AllowMultipleValues
    {
        get { return true; }
    }

    public virtual string ParameterName
    {
        get { return this.Title; }
    }

    public virtual ReadOnlyCollection<string> ParameterValues
    {
        get { return new ReadOnlyCollection<string>(m_Values); }
    }

    private string[] m_Values;

    protected override void OnInit(EventArgs e)
    {
        var userCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
        var lcid = userCulture.LCID;
        switch (lcid)
        {
            case 1036:
                m_Values = new string[] { "fr", "fre", "fra", "français", "french", "1036" };
                break;

            case 1033:
            default: // Default to english
                m_Values = new string[] { "en", "eng", "enu", "anglais", "english", "1033" };
                break;
        }
        base.OnInit(e);
    }

    [System.Web.UI.WebControls.WebParts.ConnectionProvider("User's language filter", "ITransformableFilterValues", AllowsMultipleConnections = true)]
    public ITransformableFilterValues SetConnectionInterface()
    {
        return this;
    }

    [Browsable(false)]
    public override bool Hidden
    {
        get
        {
            if (base.WebPartManager != null)
            {
                return !base.WebPartManager.DisplayMode.AllowPageDesign;
            }
            return base.Hidden;
        }
        set
        {
            base.Hidden = value;
        }
    }
}

The language detection is working, but only the first value is passed as filter. In my case, only items with fr or en are shown, even if other matching values exists.

What is missing or wrong in my code?

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.