Check if a SharePoint list item exists based on a unique URL field

Just a quick one I had to do today – check the contents of a SharePoint list and check if an item is unique based on a URL field (ie if it was a list of links then make sure the same link is not added to the list twice).

I wrote the following method which handled this perfectly:

private bool CheckItemExists(SPList list, SPFolder folder, string urlValue)
{
SPQuery query = new SPQuery();
if (folder != null)
{
query.Folder = folder;
}
query.Query = @”
<Where>
<Eq>
<FieldRef Name=’URL’ />
<Value Type=’Text’>” + urlValue + @”</Value>
</Eq>
</Where>”;
SPListItemCollection found = list.GetItems(query);
return (found.Count > 0);
}

Posted in SharePoint | Tagged , | Leave a comment

K2 SmartObject error after deleting SmartObject directly from database

If you ever see an error in K2 where you click to view your SmartObjects and you get a exception saying there is a missing object and it references a GUID OR you see the following error in your event log ‘1 Invalid archive type’ then you have no doubt done what I did, and deleted a SmartObject directly from the database in K2 (which I really DON’T recommend doing!).

If you have however done this, then when you clean up all the data from the database make sure you delete the record in the Categories database, and specifically the CategoriesData table. You will find the GUID from the error that keeps popping up in in the ‘data’ column of this database. Once you delete the problem row you K2 environment should return to normal (though you might need to restart the K2 service). This will also fix issues with the SmartObject service, as this also will NOT work whilst there is a rogue row in the CategoriesData table.

Posted in Uncategorized | Tagged , , , | Leave a comment

Changing the langauge of the SharePoint spell checker

I recently realised that regardless of what language you have set your locale or settings to in your SharePoint instance that the spellchecker dictionary ALWAYS defaults to US English – however a client of mine wanted to use the Australian English as their site was hosted and used primarily by Australians!

I thought this was going to be an easy configuration change, however in the end this required a bit of javascript injected into the page.

Basically all you need to do is add the following to the masterpage and set the correct value for the locale that you want:

<script language=”javascript” type=”text/javascript”>
L_Language_Text = 3081;
</script>

Once this is added the default dictionary is changed. I have included a table below of the common dictionaries for the various English languages. For a complete list of locales check out the following site here: http://msdn.microsoft.com/en-us/goglobal/bb964664.

English – United States – 1033
English – United Kingdom – 2057
English – Australia – 3081
English – Belize – 10249
English – Canada – 4105
English – Caribbean – 9225
English – Hong Kong SAR – 15369
English – India – 16393
English – Indonesia – 14345
English – Ireland – 6153
English – Jamaica – 8201
English – Malaysia – 17417
English – New Zealand – 5129
English – Philippines – 13321
English – Singapore – 18441
English – South Africa – 7177
English – Trinidad – 11273
English – Zimbabwe – 12297

Posted in SharePoint | 4 Comments

SeSecurityPrivilege error when trying to install SharePoint 2010

If you get the ‘SeSecurityPrivilege’ error when trying to install SharePoint 2010 – this is due to not having adequate permissions with the account you are using. This can often be caused by the permissions your account has in Active Directory. Luckily there is a way to get around this on the local machine you are using.

 In order to fix this you will need to do the following:

Go to > Local Security Policy- > Local Policies -> User Rights Assignment on the server you are trying to install on.

Assign your logged in account (eg [domain]/[username]) the following rights:

  • Back up files and directories
  • Debug Programs
  • Manage auditing and Security log
  • Restore files and directories
  • Take ownership of files or other objects

Once you have done this, log out then log back in again.
After this the installer should now work!

Posted in SharePoint | Leave a comment

Binding multiple properties to single field in WPF

On several occassions I have wanted to bind a number of properties from my View Model to a single control in my view. Luckily there is an easy way to do this with WPF – using multibinding. Examples are better than words so if you want to do this just do this…

<ListBox ItemsSource=”{StaticResource MyData}”>
  <ListBox.ItemTemplate>
    <DataTemplate>
      <TextBlock>
        <TextBlock.Text>
          <MultiBinding  StringFormat=”{}{0} — Now only {1:C}!”>
            <Binding Path=”Description”/>
            <Binding Path=”Price”/>
          </MultiBinding>
        </TextBlock.Text>
      </TextBlock>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

Thanks to http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat.aspx

Posted in c#, WPF | Leave a comment

Fading visibility in and out in WPF

I was recently looking for an easy way to fade visibility in, and then out (after a few seconds) in WPF. I thought this would be great for ‘success’ messages or something similiar. Turns out it is a piece of cake using a simple style trigger on the style for your control.

Here is my basic implementation:

<Style.Triggers>
    <Trigger Property=”Text” Value=””>
        <Setter Property=”Visibility” Value=”Collapsed” />
    </Trigger>
    <Trigger Property=”Text” Value=”{x:Null}”>
        <Setter Property=”Visibility” Value=”Collapsed” />
    </Trigger>
    <Trigger Property=”Visibility” Value=”Visible”>
        <Trigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty=”Opacity” Duration=”00:00:00″ BeginTime=”00:00:00″ From=”0.0″ To=”1.0″ />
                    <DoubleAnimation Storyboard.TargetProperty=”Opacity” Duration=”00:00:03″ BeginTime=”00:00:10″ From=”1.0″ To=”0.0″ />
                </Storyboard>
            </BeginStoryboard>
        </Trigger.EnterActions>
    </Trigger>
</Style.Triggers>

Posted in WPF, XAML | Leave a comment

Updating SPListItem’s in a SPListItemCollection

Wow! Can’t believe I haven’t discovered this before, but you can NOT directly update a SharePoint list item in a SPListItemCollection. Basically you need to reference the item you are going to update as an SPListItem and update that for it to work.

ie this does NOT work:

SPListItemCollection productMatches = currentWeb.Lists[“SomeList”].GetItems(query);
productMatches[0][“UpdatedValue”] = true;
productMatches[0].Update();

Where as this DOES work:

SPListItemCollection productMatches = currentWeb.Lists[“SomeList”].GetItems(query);
SPListItem someItem = productMatches[0];
someItem[“UpdatedValue”] = true;
someItem.Update();

Funny how such simple things can elude you for so many years… 😉

Posted in SharePoint | 2 Comments

Windows Phone 7 Development

Super Size Me Screen Shot

Super Size Me Screen Shot

I am very excited to have submitted my very first application to the Windows Phone 7 marketplace. Over the next few months I intend on creating some more and adding them to the marketplace. As a result some of my SharePoint work I am doing and have been working on is going to be on the back burner a bit.

What this does mean though is that I am (and have been) learning a whole lot of new things around the Windows Phone 7 development experience – especially around Silverlight, Azure and Expression – so I intend on doing some posts to this blog around some of my discoveries.

If you are interested in reading about my very first application you can check out my company website Cherry Byte Software for more information. Like here, I plan on doing regular updates there on the applications that are coming out!

Posted in Windows Phone 7 | Leave a comment

Upgrading Visual Studio 2010 Test Projects

Just recently upgraded a VS2010 Test Project and kept getting the following error whenever I tried to run any tests:

Object of type ‘Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext’ cannot be converted to type ‘Microsoft.VisualStudio.TestTools.UnitTesting.TestContext’

Solution – the assembly Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll is using the wrong version (9.0.0.0 instead of 10.0.0.0). Simply remove the reference toMicrosoft.VisualStudio.QualityTools.UnitTestFramework.dll and then add the reference again but using the 10.0.0.0 version!

Posted in Visual Studio | 1 Comment

Viewing the contents of a SharePoint List or Site Definition file (STP)

Wow! I can not believe that I just discovered that you can easily view the contents of an exported list or site definition in SharePoint. I had always exported then reimported these files to get the definitions – however it is actually as simple as renaming the .stp file to a .cab file, then you can easily view the contents of the site or list definition! Most of this is in a pretty meaty manifest.xml file – but it is definitely handy to know and be able to do.
Posted in SharePoint | Leave a comment