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”]));
//enContext.Load(collListItem);
enContext.ExecuteQuery();

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

References:

MSDN: Create a client app

MSDN: Retrieve List Items

MSDN: Create, Update, and Delete List Items

Advertisements

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)

$results.rows.count

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

References:
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:

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$site = new-object Microsoft.SharePoint.SPSite(“<site collection url>”)
$farm = $site.webapplication.farm
$file = $farm.solutions.item(“siterequest.wsp”).solutionfile
$file.SaveAs(“<path>\siterequest.wsp”)

 

Using PowerPoint to create SharePoint Themes

Something interesting I learned recently about SharePoint 2010 was the fact that you can use powerpoint themes as sharepoint themes.

Steps:

1. Open PowerPoint (I’m using PowerPoint 2007)
2.  Under the “Design” tab, choose a theme and specify your preferred color schema

pptTheme
3. Save the file in “Office Theme” (*.thmx) format
4. Navigate to the site settings of your SharePoint site collection and go to the Themes gallery
5. Click “Upload Document” from the ribbon and upload the theme file that you previously saved – you should now see your theme within the Theme gallery
6.  Go back to site settings and click “Site theme” under the “Look and Feel” category to change the site theme
7. You should now be able to select the theme you uploaded and even further customize the colors/fonts.

spTheme
8. Once you apply your theme, you should see the changes!

modifiedSite

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:

manifest

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: http://envisionthepossible.com

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

http://blogs.technet.com/b/cbortlik/archive/2010/04/27/learning-to-crawl-walk-and-run-with-sharepoint.aspx

Must-Have (Free Resources):

  • iUseSharePoint.com

Getting Buy In:

Forrester study shows positive ROI in roughly 9 months: http://tinyurl.com/sp2010roi

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

SPC2011: How the SharePoint Dev Team Troubleshoots Performance and Reliability

Notes from the SharePoint Conference 2011
Session:  How the SharePoint Dev Team Troubleshoots Performance and Reliability

SPMonitoredScope

  • captures performance
  • have one outer monitored scope to identify code
  • wrap calls to external code in monitored scope
  • specify SQL & SPRequestCounter
  • do not use in a for loop (due to resources)

Developer Dashboard

  • Can include SPMonitored scopes (unless its for sandbox)
  • Includes header and trace information

Caveats to the Developer Dashboard

  • available to all site administrators
  • trace logs may contain sensitive information
  • Only for aspx – not with ajax, scripts, office rich clients requests

Usage database

  • IIS logs
  • timer job executions
  • event logs
  • SQL queries (blocking, deadlock)

Caveats to Usage database

  • 7 day retention default (can change)
  • failed requests wont appear
  • SQL is costly for usage
  • only works for single farm

SPDiagnostic Studio 2010

  • troubleshoot visually

Caveats to SPDiagnostic Studio 2010

  • built for internal
  • not ideal for monitoring
  • good for bug finding/exploration