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>”;

 

 

 

Advertisements

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