CAML Query using Date Ranges

Having trouble getting any results back when querying a SharePoint list for items within a date range? It may be that you haven’t converted your variable dates to the ISO 8601 format that SharePoint expects for date values in CAML queries. You can do this by using the SPUtility.CreateISO8601DateTimeFromSystemDateTime() method. Make sure the dates you are converting are in UTC or local time first though!

An example is below:

string Iso8601startDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(startDate);

string Iso8601Today = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today.AddDays(1));

            if (spList != null)

            {

                SPQuery qry = new SPQuery();

                qry.Query =

                @”   <Where>

                          <And>

                             <Gt>

                                <FieldRef Name=’DateSubmitted’ />

                                <Value Type=’DateTime’ IncludeTimeValue=’FALSE’>” + Iso8601startDate +

                                @” </Value>

                             </Gt>

                             <Lt>

                                <FieldRef Name=’DateSubmitted’ />

                                <Value Type=’DateTime’ IncludeTimeValue=’FALSE’>” + Iso8601Today +

                                @”</Value>

                             </Lt>

                          </And>

                       </Where>

                       <OrderBy>

                          <FieldRef Name=’DateSubmitted’ />

                       </OrderBy>”;

 

 

 

Error When Creating Links List Items (Hyperlinks)

In my case, I was using PowerShell to create a bunch of links to folders on a file-share in a SharePoint list. I came across errors when I used the 2010 method in 2013. Below I have provided examples of each method:

2010

$urlValue = New-Object Microsoft.SharePoint.SPFieldUrlValue("")
$urlValue.Description = "This is an awesome description"
$urlValue.Url =  "http://MyUrl.com"
$item["URL"] = $urlValue
$item.update()

2013

$newItem = $list.Items.Add()
$newItem["URL"] = "$urlString , $descriptionString"
$newItem["Comments"] = $descriptionString
$newItem.Update()

 

Error 0x80070002 – Deploying Event Receiver

When using Visual Studio to package and deploy an event receiver to be associated with  SharePoint list, you may come across this error:

Error occurred in deployment step ‘Activate Features’: <nativehr>0x80070002</nativehr>

This probably means that your List URL is incorrect in the receiver elements file. The format needs to be :

<Receivers ListUrl="Lists/TestAnnouncements">

You may also see a Invalid Function error when you try to activate the feature manually in your site. Double check the URL of your list and ensure the list either exists or is being created at this URL prior to the receiver activation.

Where can I activate web application features?

In SharePoint 2010 and 2013, it is a bit tricky to find the list of features to activate or deactivate so I thought I’d leave some breadcrumbs here for folks to follow:

SharePoint 2010/2013:
In Central Admin click Application Management > Manage Web Application then click the relevant Web Application name to highlight it. Finally, in the ribbon, click Manage features.
SharePoint 2007:
In Central Admin click Application Management > Manage Web application features
If you can’t find the feature you are looking for in these lists, you have either:
Not installed the feature
Installed a feature scoped at a different level (i.e. not web application scope).
Happy Activations!

User cannot be found – Workflow Error

After migrating a SharePoint site to a new collection; which utilised a globally reusable SPD workflow, I of course expected that the workflow would not be available to the migrated sub site until I published an update. What I didn’t expect though was that updating the workflow would break it everywhere.

First of all I tried updating the workflow settings on the content type (in this case Document) to cascade the workflow settings down to all child content types (including those in the migrated sub site). This got me one step closer to my goal as the workflow then appeared associated with documents in the sub site, BUT once I tried to start a workflow, I got a big fat error: User cannot be found.

So next I opened SPD and updated the workflow and republished it (globally). That all worked and so I tested the workflow in the sub site again- User cannot be found.

So next came Google. I found plenty of people reporting the issue and many of those also bagged Microsoft for telling them that it could be fixed by simply re-publishing the workflow. Since I’d already tried that, I sympathised with their frustration.

Finally, with the magic of Google, I found this post which gave me the right answer. I logged in as an SCA and deactivated and then activated the site collection workflow feature and then started a workflow in my sub site.. Success!

workflow

Display All Appending Field Entries in a Single List View

Saving a list  template with content and then creating a list using that template doesn’t bring across append field history. This is to be expected really but it’s a pain if you are trying to migrate the content to a new site collection. I found a cool way to get around this though; which requires manually copying the append history into the destination list’s datasheet view. To be able to do this, you first need a way of displaying all the appended comments together (viewing append fields in the item display form or library views only show the latest entry). Below I will describe how to do this. I’m sure there are other good reasons to display all append entries in one view but here I will outline the steps to migrate the content:

1.     Add your newly created list (from template with content) to a blank web part page (as a list web part). Make sure the current view is displaying the append field and any others you are interested in.

2.     Export the list web part file by following the instructions in this post (who wrote this? It is friggin awesome!)

3.     Edit the file and you will see the XSLLink property points to the main.xsl file. Download this file and rename to main_showappend.xsl

4.     Edit main_showappend.xsl and take note of the import of fldtypes.xsl. Download this file and rename to fldtypes_showappend.xsl

5.     Upload both fldtypes_showappend.xsl and main_showappend.xsl to a library in your SharePoint site and then Edit main_showappend.xsl to update the import ref to point to your   fldtypes_showappend.xsl

6.     Now edit fldtypes_showappend.xsl and find the FieldRef_Note_body template. Update as below:

<xsl:template name=”FieldRef_Note_body” ddwrt:dvt_mode=”body” match=”FieldRef” mode=”Note_body”>

<xsl:param name=”thisNode” select=”.”/>

<div dir=”{@Direction}”>

<SharePoint:AppendOnlyHistory FieldName=”MyAppendField” runat=”server” ControlMode=”Display” ItemId=”{$thisNode/@ID}”/>

</div>

</xsl:template>

7.     So now you have 3 filesmain_showappend.xsl is in SharePoint and imports fldtypes_showappend.xsl from your SharePoint library. Your list web part file is open on your desktop. Update this file to point the XSLLink value to  the URL of main_showappend.xsl in SharePoint. Save the file.

8.     Now return to your web part page in SharePoint. Delete the current list web part and import your custom web part file. Voila! Now you should see your list displaying the append field entries all together.

AppendFields

9.     Now you can “page scrape” this page to copy the append field values- organize in an excel spreadsheet if you need to, and then paste into the new list datasheet view. I actually turned off append while I did this and then turned it back on afterwards. This gives all your historic entries in one entry and then allows you to continue to append single comments going forward.

Hope this was helpful.

e

Exporting a List Web Part – Made Easy

So as you already know, list web parts are not exportable via the UI menus. That option is inconveniently missing. There are a few ways however, to get around this but the option I will describe here does NOT require SharePoint designer. Now, now, quiet down with the cheering and the celebration and follow these simple steps:

  1. Navigate to the list you want to export as a web part and Edit the page
  2. Open your browser’s Dev Tools and search the HTML for MSOMenu_Export
  3. If you examine the attributes of this menu item, you should see the onmenuclick Javascript. Copy the Javascript call
  4. In your list page, open the list web part menu (as if you were going to delete/minimise/export it). This is very important.
  5. Paste the Javascript into the browser URL bar and hit enter
  6. Now you are prompted to Save or Open the .webpart file and voila!

Can’t Check Documents In: Missing Required Metadata

There could be a number of reasons for this issue; the most obvious being that you just haven’t completed the mandatory metadata on your document before checking  it in. However, I am assuming you are a little more cluey than that.

If you are dealing with a MS Office document (particularly Excel) and you are being diligent and filling out the required metadata in the DIP, saving and then trying to check it in and you are still being told you haven’t completed all the required metadata then I suspect the problem may be with Password Protection on the document or a workbook inside. Here is a good little summary of the issue.

The work around, while the desktop guys scramble around trying to tweak the group policy, is to close the document without checking it in, navigate to the document in the SharePoint document library and then Edit the properties of the document and set them in the Edit Metadata Form. When satisfied, check the document in via the library ribbon. Unfortunately this must happen every time the document is checked out for Edit. The same properties will always be wiped by the check in. If you can just turn off Protection on the document then that will stifle the issue as well. Depending on the business requirement, this may not be appropriate though.

Alternatively if Password Protection/Encryption is not your problem, then I must ask you whether you are using Lookup lists values as metadata in your document library? If so, make sure that the users trying to fillout the metadata and check the document in actually have sufficient access to the source Lookup list. If they don’t, they won’t be able to complete that piece of metadata.

Changing a List URL in SharePoint 2010

A quick way to do this is to use SharePoint Designer 2010. Open the site containing your list (your account must have appropriate level of access to update lists).  Go to All Files then right click the list/library you want to update and select Rename. The Name Column (first) effects the URL, the Title column; the list name. Don’t forget, if you have any hard coded links anywhere, you must update those. If the List’s ‘Display this document library on the Quick Launch’ setting is on, then the Site Navigation will update automatically to point to the new URL.