1

I'm trying to retrieve a user's profile picture from the hidden User Information List within Silverlight. I can't use the UserProfileService.asmx because I don't have the login name nor the GUID of the user. I do have the user's ID (matching the ID field of this list) and the user's display name (as: "FirstName LastName"), because I have this data from a FieldUserValue (blog author). I have tried to rewrite this function by passing the ID, by using Linq, by calling Load() on every intermediary object (which should be unnecessary), by calling GetItemByID(int ID), by pulling the list by name (GetListByName("User Information List")) as opposed to using Web.SiteUserInfoList... and I'm stuck. None are working.

    ListItemCollection licAuthors; //<=== Global, should only return 1 user, but
                                   //     the query returns a collection anyhow
    private void GetUserLogin(string strUserName)
    {
        ClientContext ctx = new ClientContext("http://mydevsite/");

        CamlQuery cqUserName = new CamlQuery();
        cqUserName.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title' />" +
            "<Value Type='String'>" + strUserName + "</Value></Eq></Where></Query>" +
            "<ViewFields><FieldRef Name='Title'/><FieldRef Name='Picture'/>" +
            "</ViewFields></View>";

        licAuthors = ctx.Web.SiteUserInfoList.GetItems(cqUserName);
        ctx.Load(licAuthors);

        ctx.ExecuteQueryAsync((s, e) => { getbloginfoFinished.Set(); },
            (s, e) => { getbloginfoFinished.Set(); });
    }

Is this some kind of permissions issue because it's Silverlight? My user login has all permissions possible to access this list.

Should I be using the /_vti_bin/Lists.asmx web service?

Is pulling this information from this list going to cause permissions issues for users without full permissions?

Any help would be appreciated.

The information sources I've used thus far to try to achieve this are:

http://www.zimmergren.net/technical/sharepoints-hidden-user-list-user-information-list

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/3462eb55-8dc5-4c81-be98-1f48d8192cbf/

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/61645e0a-7e95-434a-ba04-54d399f501f4/

To summarize:

My end goal is to retrieve the url to a user's profile picture, given a FieldUserValue ("Created By") of a blog post, from a blog site, which is pulled from the "Posts" list.

9
  • Can't you just set the Created By filed to display as Named (with picture and details)? I haven't tried setting that as the option and fetching data via the web services to see what it returns, just a shot in the dark. Commented Apr 12, 2012 at 17:39
  • Taking your advice I can see the picture in the list, yes. But how do I access the url to display the author's image in my Silverlight app on the portal landing page? Commented Apr 12, 2012 at 18:20
  • If you try to fetch the Created By information with your Silverlight app when the field is set that way, does it return all the html with it? I know in DVWPs, the returned content is different depending on how the Created By field is formated. Commented Apr 12, 2012 at 18:46
  • No, there's no more data. I'm still working on it. I've got it returning a user by ID... but the ID's don't match and passing my LookupId is returning the administrator account... but I'm trudging through it. Commented Apr 12, 2012 at 18:56
  • Do you know what "Type" the value of ImnName (The user name field) is for a CamlQuery? Commented Apr 12, 2012 at 19:07

2 Answers 2

3

I solved it. For posterity:

        CamlQuery cqUserName = new CamlQuery();
        foreach (ListItem liItem in oListInfo)
        {
            FieldUserValue fuvAuthor = (FieldUserValue)liItem["Author"];
            cqUserName.ViewXml = "<View><Query><Where><Eq><FieldRef Name='ID' />" +
                "<Value Type='Integer'>" + fuvAuthor.LookupId.ToString() + "</Value>" +
                "</Eq></Where></Query><ViewFields><FieldRef Name='Picture'/>" +
                "</ViewFields></View>";
        }

        ClientContext ctx = new ClientContext(strSiteRoot + "/");
        ListItemCollection licAuthors = ctx.Web.SiteUserInfoList.GetItems(cqUserName);

        ctx.Load(licAuthors);
        ctx.ExecuteQuery();

        foreach (ListItem liAuthor in licAuthors)
        {
            FieldUrlValue fuvPicture = (FieldUrlValue)liAuthor["Picture"];
            imgUri = new Uri(fuvPicture.Url);
        }

Instead of calling:

 GetItemByID(fuvAuthor.LookupId);

The user ID and the internal list ID of the User Information List apparently are not the same.

2

The following will also work:

cqUserName.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title' />" +
            "<Value Type='Text'>" + strUserName + "</Value></Eq></Where></Query>" +
            "<ViewFields><FieldRef Name='Title'/><FieldRef Name='Picture'/>" +
            "</ViewFields></View>";

The Value Type attribute should be "Text" and not "String".

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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