development
27 08 2013
Trying never to use SPList.Items (due to Best Practice), yet needing to grab some items from a list quite often? Here’s an extension method which I use a fair bit.
|
/// <summary> /// Gets items where a property matches a value /// </summary> /// <param name="list">The list.</param> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <returns>A list collection of SPListItems</returns> public static IList<SPListItem> ItemsWhere(this SPList list, string property, string value) { SPQuery query = new SPQuery(); query.Query = string.Format("<Where><Eq><FieldRef Name='{0}' /><Value Type='Text'>{1}</Value></Eq></Where>", property, value); SPListItemCollection items = list.GetItems(query); return items.Cast<SPListItem>().ToList(); } |
You can then use regular LINQ queries to get the item or items you need against the object returned by this, for example:
|
SPList webPartCatalog = site.GetCatalog(SPListTemplateType.WebPartCatalog); SPListItem wpItem = webPartCatalog.ItemsWhere("FileLeafRef", "Some Web Part.dwp").FirstOrDefault(); |
[…]
2 08 2013
Here’s a quickie – in SharePoint Sites and Lists, you have the option to let the search indexer crawl the content, setting the “Allow this site to appear in search results”. This is a property on the relevant object called ‘NoCrawl‘. Just set this to true to prevent indexing of the object, or false to […]
1 08 2013
Scenario: You’ve programmatically provisioned some Content Organizer Rules to send some documents somewhere based on a Managed Metadata Field. When you upload a document and set that field to something matching a condition, it throws an error, and you see this in the event logs:
|
Routing Engine: EvaluateCondition threw an exception. rField: <guid>|<field internal name>|<field title>, objParams[0]: <metadata label>|<term id>, objParams[1]: <wssid>;#<metadata label>|<term id>, condition.ColumnType: Invalid, condition.ColumnName: <field id>|<field internal name>|<field title>, op: Contains |
The thing to watch here is the last bit […]
14 05 2013
Over on my Github project I have finally got round to doing some updates to the code. I’ve added a class that simplifies Forms Authentication, and allows you to issue the same REST API queries against SharePoint. Code samples are on the wiki on the Github site. Doing this wasn’t really that difficult, you basically […]
25 04 2013
(Concepts here are discussed around SharePoint 2010 but should equally be applicable to SharePoint 2013. All concepts here apply only to full-trust farm solutions, and cannot be done at all with Sandboxed solutions or with the App model)Occasionally you might give given the requirement (as a developer) to provide the ability to insert a chart […]
22 04 2013
Here’s some code to get all PerformancePoint filter selections for the current user in a web site. This is a fairly straightforward operation. First you need a collection of strings, each of which is the URL to a PerformancePoint Filter stored in SharePoint. In this code snippet I use SPSiteDataQuery (in the DiscoverFilterUrls() method). You […]
19 04 2013
For a beginner SharePoint developer, there can be a fair amount of confusion around the seemingly trivial task of building a C# Console Application to connect to a SharePoint site and to learn the object model. You merely include a reference to the Microsoft.SharePoint.dll assembly, instantiate an object, passing in your site URL and you’re […]
19 04 2013
Here’s a code sample which will give you a web part that will have a property (accessible via the Toolpane) that lets you define a semi-colon separated list of the names of Filter Connection points. You can then use any standard SharePoint (or even PerformancePoint) filters connected to the web part and use them how […]
21 03 2013
If you’re doing development against PerformancePoint Services API, whether in a custom ASP.NET site, a Console Application, make sure you have the Bpm configSection within your web.config (or App.config). You want to add the following configSection to your config file:
|
<configSections> <sectionGroup name="Bpm"> <section name="FCODaoProviders" type="System.Configuration.DictionarySectionHandler" /> </sectionGroup> </configSections> |
And you also want to include this under the root element of your […]
13 12 2012
NOTICE: This post refers to my initial version of an attempt at this API. This version is now deprecated, please use the version detailed here instead. This post and the included code is the result of a couple of weeks of confusion, hard work and a tonne of research and collaboration between myself and Becky […]