Client Object Model: Query Approved Items and Add Them to Another List

Played around with client object model today to query for approved items and add them to another list.

string rootSite = “<rootSiteUrl>”;
ClientContext rootContext = new ClientContext(rootSite);

string enSite = “<otherSiteUrl>”;
ClientContext enContext = new ClientContext(enSite);

NetworkCredential credentials = new NetworkCredential(“username”, “password”, “domain”);
rootContext.Credentials = credentials;
enContext.Credentials = credentials;

SP.List syndList = rootContext.Web.Lists.GetByTitle(“<List1Name>”);
SP.List pagesLibrary = enContext.Web.Lists.GetByTitle(“<List2Name>”);

CamlQuery camlQuery = new CamlQuery();
//Approved=0, Rejected=1, Pending=2, Draft=3, Scheduled=4
camlQuery.ViewXml = “<View><Query><Where><Eq><FieldRef Name=’_ModerationStatus’/><Value Type=’ModStat’>0</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>”;

ListItemCollection collListItem = pagesLibrary.GetItems(camlQuery);

enContext.Load(collListItem, items => items.Include
(item => item[“Title”],
item => item[“FileRef”]));

foreach (ListItem oListItem in collListItem)
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = syndList.AddItem(itemCreateInfo);
newItem[“Title”] = oListItem[“Title”];
newItem[“PageURL”] = rootSite+oListItem[“FileRef”];


MSDN: Create a client app

MSDN: Retrieve List Items

MSDN: Create, Update, and Delete List Items


Using SPSiteDataQuery with Powershell

I admit it – I didn’t realize that you could use SPSiteDataQuery in SharePoint 2007. I totally thought it was specific to 2010. I tried using it in powershell so that I could get specific lists/libraries within a site collection. Here’s what the general code looks like:

$site = new-object Microsoft.SharePoint.SPSite(“<url>”)

$query = new-object Microsoft.SharePoint.SPSiteDataQuery

$query.ViewFields = “<FieldRef Name=’Title’ />”

$query.Webs = “<Webs Scope=’SiteCollection’ />”

$query.Lists = “<Lists ServerTemplate=’101′ Hidden=’false’ />”

$results = new-object System.Data.DataTable

$results = $site.rootweb.GetSiteData($query)


foreach($row in $results.rows)


Write-host $row.Title


I learned some things along the way. Like SPSiteDataQuery is kind of limiting.  Below are some lessons I learned:

1. So far I know the result gets ListID, WebID, and SPListItem ID returned by default.

2. A lowercase or spelling mistake either returns an error or no results – it took me awhile to realize that.

3. Search results can be incomplete when you use a CAML query that uses the SPSiteDataQuery class to search content on a SharePoint server 2007 or Windows SharePoint Services 3.0 site. According to the KB, the problem occurs when:

    • The CAML query searches for content in more than 10 document libraries or document lists.
    • The CAML query searches for content across more than 10 explicit GUIDs.

The following condition must also be true:

    • The column mapping for a field in the Where clause is not the same in all the document libraries, in all the document lists, or in all the GUIDs in the query.

4. There wasn’t an easy way to only get items that were created by users (I wanted to exclude items that were in system created documents libraries like “Style Library”). The only thing I could find was getting the author field and excluding items where author is equal to Sharepoint\system.

5. You can only specify one list type at a time (for example, I can’t get back all custom lists and document libraries within one query).

6. You can only include/exclude specific lists by hardcoding the list id

MSDN: SPSiteDataQuery class

Extract a wsp using Powershell (SharePoint 2007)

I just found a cool way to extract a wsp that has already been deployed using powershell:

$site = new-object Microsoft.SharePoint.SPSite(“<site collection url>”)
$farm = $
$file = $“siterequest.wsp”).solutionfile


Using BindingRedirects for Web Part Versions

Today I found out how easy it is to use BindingRedirect tags in SharePoint 2010 to have two different versions of a web part. Having this option is helpful in the event that you’ve updated a web part with a new version but sites are using the older version.

In SharePoint 2007 you had to use SPWebModification to update the web.config but in SharePoint 2010, all you have to do is add the tags to the solution manifest!

Once you’ve incremented the assembly version in the AssemblyInfo.cs, double-click on “Package” to get to the manifest and add the bindingRedirect tags and safeControl entry of the older version in the “Edit Options” section. It should look something similar to this:


Once you’ve deployed the solution, if you look in the web.config you can see that both versions are there and there is a bindingRedirect tag added in the <assemblyBinding> area:




SPC2011: Drive Adoption and Get Users Excited About SharePoint (SPC102)

Notes from the SharePoint Conference 2011
Session:  Drive Adoption and Get Users Excited About SharePoint (SPC102)
Speakers: Scott Jamison, Chris Bortlik

I’m always interested to hear about how others drive user adoption for SharePoint because in my opinion, it IS hard to get users to adopt SharePoint. Let’s face it – SharePoint is big/complex and its got its quirks and you really have to spend time playing around with it before you can start getting use out of it.

In this session, they used an example of VHS over Betamax to point out that even though Betamax was the better technology, VHS won out in the end because it had better content (this was all before my time so I’ll take their word for it). It’s content that drives user adoption, not the technology.

Another point that they made was that SharePoint adoption is hard because people don’t need to use SharePoint to do collaboration – People have been sending and resending documents to each other as attachments in emails  for forever.

Connect SharePoint with user’s business goals

What is the driving factor? (not requirements like this button should be red)

Good site design

What’s in it for me? How will it help my job? –> need to show how it will actually help them

Elements for Adoption Strategy:

Communication Plan

    • Leverage experts and champions
    • Town hall meetings
    • Break Room poster
    • Online scavenger hunts
    • Launch Parties
    • *Ongoing communication!*

Training Plan

    • Training for Power Users, Visitors, Members, Contributors
    • “Just in time and just enough” – ie. 60 second videos

Content Conversion Plan (for migrating data from legacy systems)

    • Clean and migrate recent content only
    • Trash in = trash out

User Support Plan

    • Contact person for every page
    • Internal User Groups
    • Get the IT help desk on board
    • End user feedback loop! Get evidence that SharePoint is better for them!
    • Training guides

Incentives and Reward Plan

    • Show with real data why something is useful
    • Make it fun!
    • Recognition for Content Contribution (ie. Leader board)
    • Example – Microsoft Academy Content Contributions

Executive Sponsorship Plan

    • Getting Executive buy in: not just numbers, its intangibles like productivity gains, employee retention, community)

Information Architecture Plan

    • If it’s not easy to find, users will give up (going back to good site design)
    • Branding
    • Simplify templates – don’t just turn everything on!

Governance Plan

Find your Killer Application:

Adoption = Value > Change

Using SharePoint as a glorified file share is not enough to adopt

Find where users need to use SharePoint (critical business process/flow) – Mostly around automation

Using surveys to get user buy-in/opinion/support

Microsoft Experience Center:

Examples of killer apps:

  • Youtube for the Enterprise

Motto: Crawl, Walk, Run

Don’t need to know how to do everything at once

Just in time training as roll out different functionality

Must-Have (Free Resources):


Getting Buy In:

Forrester study shows positive ROI in roughly 9 months:

This was a good session – I liked everything they were saying!

SPC2011: Out of the Sandbox and into the cloud: Build your next SharePoint app on Azure

Notes from the SharePoint Conference 2011
Session:  Out of the Sandbox and into the cloud: Build your next SharePoint app on Azure

Using Windows Azure as a workaround for sandbox solution limitations in SharePoint Online

How to get around sandbox solution limitations

  • Fully trusted proxy
  • Client side web part that contains javascript and jquery
  • Silverlight web part

How to consume Azure based solution in SharePoint

  • Content Editor web part
  • Sandbox solution web party
  • BCS
  • Search

How to enable Azure based solutions to interact with SharePoint

  • Client Object Model
  • REST
  • SPS Authentication configurations (ie. Classic mode, Claims based)


  • Using an IFRAME to show Azure content in SharePoint site
  • Using a Content Editor web part that contains javascript/async JSON to access the Odata svc
  • See Andrew Connell’s blog for more information/materials
  • Check out the Azure learning kit

SPC2011: Understanding SharePoint Administration, Part 1

Notes from the SharePoint Conference 2011
Session: Understanding SharePoint Administration, Part 1

Discussed infrastructure best practices, virtualization, hardware/software requirements and installation


  • Have SQL server on a separate server
  • Use load balancing
  • Need a server license for all SharePoint servers
  • Consider search on a separate server – Crawling will not affect web front ends
  • Consider separate index servers for large document capacity

Production environment

  • 100 GB C drive (used by e. 14 hive)
  • X GB second drive (move all possible files such as logs)
  • 4 cores
  • 8 GB RAM
  • Make sure that you have the same drives on each server
  • All servers need to be in the same datacenter


  • Web front ends – sure
  • Application – usually
  • SQL – never
  • Reference: Todd Klindt’s blog on sp2010 hardware/software requirements

Development environment

  • Need at least 4 GB RAM
  • Can run on Windows 7 or Vista but never for PROD

Test environment

  • Developers should have zero access to test servers
  • Should be multi-server if PROD is


1. Prereq installer

2. Installing the bits (setup.exe)

  • Install on all servers at the same time
  • Use admin account
  • Do not do standalone install
  • Uncheck the box to run the config wizard – will run later

3. Configure the bits (powershell)

  • Powershell: New-SPConfigurationDatabase
  • Now run config wizards on each server – can run all at the same time
  • Use NTLM

4. Farm configuration (powershell/central admin)

  • Manually provision servers (if do automatic, may get strange names)
  • Use powershell for service application configuration
  • Todd Klindt has a blog for cheat sheet for required service accounts to have
  • Create state service and usage and health data collection using powershell (not available via UI)