Sunday, January 22, 2012

Creating custom menus to SharePoint sites

Sometimes we need custom menus in our SharePoint sites. In this posting I will show you how to add custom xml-based menu to your master page and make it work with SharePoint.

Webinar: Afraid of the Dark? Keep SharePoint Running

2012-16-02 16:00 GMT Join SharePoint Pro for Afraid of the Dark? Keep SharePoint Running, a free online one-day conference for developers and administrators of SharePoint products and technologies. This conference brings industry experts straight to your computer, offering free, technical SharePoint High Availability training.

Webinar: Demystifying FAST Search for SharePoint

2012-15-02 18:00 GMT. Join Chris Givens, CEO of Architecting Connected Systems and Sr. Architect of the eBay SharePoint 2010 Upgrade, to explore FAST Search for SharePoint. FAST Search for SharePoint is the most common and valuable extension added to SharePoint 2010 deployments. Webinar is free.

Making SharePoint 2010 Foundation top menu using submenu popups

By default SharePoint 2010 Foundation menus are not hierarchical and we have to move from site to site using top menus or quick launch menus. In this posting I will show you how to make SharePoint 2010 Foundation top menu hierarchical so it shows submenus when user moves over menu items with mouse.

Hide ribbon using SPSecurityTrimmedControl

In one of my current SharePoint 2010 Foundation projects I needed to hide ribbon from anonymous users. Visitors, contributors etc must see ribbon on all pages where it shown by default. In this posting I will show you how to hide ribbon using SPSecurityTrimmedControl.

Thursday, December 29, 2011

Using SharePoint client object model

SharePoint 2010 has powerful client object model that you can use to write external applications that use SharePoint data. In this posting I will show you how to get data from lists using client object model and how to optimize queries to save some bandwidth.

Saturday, April 30, 2011

Using SPSiteDataQuery to find list items by unique ID

In one of my projects I had to search for list item from current site collection by its unique ID that is kept in database as GUID. In this posting I will show you how to query list items by unique ID over current site collection.

Here’s the example query that works fine for me. Take a look at query – unique ID value must be set to type Lookup.


var queryString = @"<Where>

                        <Eq>

                            <FieldRef Name='Unique' />

                            <Value Type='Lookup'>{0}</Value>

                        </Eq>

                    </Where>";           

queryString = string.Format(queryString, taskIdString);

 

var query = new SPSiteDataQuery();

query.Query = queryString;

query.Webs = "<Webs Scope='SiteCollection' />";

query.Lists = "<Lists BaseType='0' />";

query.RowLimit = 1;

query.ViewFields = "<FieldRef Name='Title' />
                    <FieldRef Name='ID' />
                    <FieldRef Name='UniqueId' />"
;


Besides fields defined in ViewFields property the results contain also web and list ID-s where item belongs.

This is the helper method I use to find workflow task with given unique ID. I’m using this code on page where workflow is not present.


public SPListItem GetListItemByUniqueId(Guid uniqueId)

{

    var queryString = @"<Where>
                       <Eq>
                       <FieldRef Name='UniqueId' />
                       <Value Type='Lookup'>{0}</Value>
                       </Eq>
                       </Where>"
;

    queryString = string.Format(queryString, uniqueId);

 

    var query = new SPSiteDataQuery();

    query.Query = queryString;

    query.Webs = "<Webs Scope='SiteCollection' />";

    query.Lists = "<Lists BaseType='0' />";

    query.RowLimit = 1;

    query.ViewFields = @"<FieldRef Name='Title' />
                         <FieldRef Name='ID' />
                         <FieldRef Name='UniqueId' />"
;

 

    var results = SPContext.Current.Web.GetSiteData(query);

    if (results == null)

    {

        return null;

    }

    if (results.Rows.Count == 0)

    {

        return null;

    }

 

    var listId = new Guid(results.Rows[0]["ListId"].ToString());

    var list = SPContext.Current.Web.Lists[listId];

    return list.GetItemByUniqueId(uniqueId);

}


As you can see there’s code enough to keep it in separate method. You can use this method in your own code and you can also modify and improve it to better fit your needs.