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 am trying to create a connectable Web Part that can connect to a SharePoint List. I have added my list to the page and I have added my custom Provider Web Part. I implemented IWebPartField but I don't necessarily think that is the right interface for what I am trying to accomplish.

My goal is to filter a list by the value of a profile property of the currently logged in user. Eventually, I'd like to replace the functionality of the "Current User Filter" Web Part to use in non-Enterprise deployments; but for now I'm just taking baby steps until I figure out the connection piece of this solution.

When I try to connect my custom Web Part to the list, I see the message, "... is not compatible with any other Web Parts on the page". What must I do to connect my Provider Web Part to a standard SharePoint list?

namespace Current_User_Filter.Current_User_Filter_Web_Part
{
[ToolboxItemAttribute(false)] 
public class Current_User_Filter_Web_Part : WebPart, IWebPartField
{
    [Personalizable()]
    public string CorpID
    {
        get
        {
            return _CorpID;
        }
        set
        {
            _CorpID = value;
        }
    }


    private String _CorpID = String.Empty;
    private string _myProperty = String.Empty;

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [System.ComponentModel.Category("Select Filter")]
    [WebDisplayName("Filter")]
    [WebDescription("Filter by the selected property of the current user")]
    public string MyProperty
    {
        get
        {
            if (_myProperty == null)
            {
                _myProperty = "Hello SharePoint!";
            }
            return _myProperty;
        }
        set { _myProperty = value; }
    }

    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        using (SPSite site = new SPSite("http://" + Page.Request.Url.Host.ToString()))
        {
            SPServiceContext context = SPServiceContext.GetContext(site);
            UserProfileManager upm = new UserProfileManager(context);

            string CurrentUserLoginName = SPContext.Current.Web.CurrentUser.LoginName;
            UserProfile CurrentUser = upm.GetUserProfile(CurrentUserLoginName);

            CorpID = CurrentUser["CorpID"].Value.ToString();
            _myProperty = CorpID;
        }
        this.Controls.Add(new LiteralControl(this.MyProperty));
    }

    [ConnectionProvider("Provider for User Profile Properties")]
    public IWebPartField GetWPConnectFieldProvider()
    {
        return this;
    }

    public void GetFieldValue(FieldCallback callback)
    {
        callback.Invoke(this.MyProperty);
    }

    public PropertyDescriptor Schema
    {
        get
        {
            return TypeDescriptor.GetProperties(this)["Provider for User Profile Properties"];
        }
    }
}

}

share|improve this question
add comment

2 Answers

What interface are you using? (HINT: post your code ;-)

Standard lists support IWebPartField, IWebPartRow, IWebPartTable and IWebPartParameters. Which you want to use depends on what you want to achieve.

Often you would like to transfer the whole row of data, so you would use IWebPartRow.

http://msdn.microsoft.com/en-us/library/ms494838%28office.12%29.aspx

share|improve this answer
add comment
up vote 0 down vote accepted

I needed to implement the ITransformableFilterValues interface.

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.