Monday 11 October 2010

SPMetal naming conventions - good practice

Problem: The Linq to SharePoint proxy generates properties using the display name of the column, additionally spaces are removed.  If you use a friendly short name you get duplicates.  The 2nd instance is appended a integer.  If you add a column with the internal name "Advert Title" and it's display name is "Title", SPMetal generates 2 properties namely: Title (the default column in all lists) and Title0, not ideal to differeintiate in code.

Resolution:  Make the display name more specific to avoid the scenario.  I.e. "Publication Title" would become the property "PublicationTitle".

Tip: Update 18 Oct 2010 - SPMetal does not like spaces in the url to the site that it generates off.  Error the web at 'http://demo.dev/sites/my site' could not be found

Friday 8 October 2010

Extending SPMetal - Retrieving Attachments from SharePoint Lists

Problem: LINQ to SharePoint does not support attachments by default.
Hypothesis: Traditional Server Object Model approach to retrieving a specific list item’s attachments.  Approach is shown below:
Resolution: Use a partial class as described by Andrew Connell to use Linq to SharePoint to work with attachments. You could hydrate the attachment (SPFile objects) in the parital class but I choose not to, in case someone in the development team used the extended mapped property for retrieving a large list. This uses the Server object model and the hydration process is extremely heavy.  This method allows me to know if there are attachments, how many and where I can get them.  With this information I only get the specific SPFile objects if I need to work with the object.  Outlined are the steps to extend LINQ to SharePoint to retrieve attachment associated to items in a list.

1) Extend the SPMetal generated proxy class
2) Get a specific item using the LINQ to SharePoint model and using the String array returned by the extended class, get the file objects using SharePoint’s server side object model.
Tip: attachments is a string array, not an array of SPFile objects. The attachements.UrlPrefix property can be used to hydrate the SPFile objects for the list item.

Tip: I upload attachments using the Dialog framework point to attachfile.aspx as it does all the work for me.
_layouts/attachfile.aspx?ListId={5555D16F-5559-4CE4-555E-F5B0E9DC5555}&IsDlg=1&ItemId=



Thursday 7 October 2010

SQL Server 2008 Service Pack 2 Released

Overview: Technet news flash email letter announced the release of SQL Server 2008 Service Pack 2 today.  I think it's been out a few days. 
http://go.microsoft.com/fwlink/?LinkId=196550
I have installed on my development machine - no issues.  If you are on Windows 2008 upgrade to SP2.  New installs should still use SQLServer 2008 R2 and ignore this Service Pack.

Wednesday 6 October 2010

jQuery intellisense

Problem: jQuery is pretty useful and I'm not great at creating it.
Hypothesis: I am using jQuery version jquery-1.4.2.js to get intellisence I need to reference jquery-1.4.1-vsdoc.js, this should be removed at deployment.  You can reference the Visual Studio jQuery Intellesense file (jquery-1.4.1-vsdoc.js) either from microsoft's CDN or deploy locally to the 14 hive.

References:
http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx
http://www.devcurry.com/2010/02/visual-studio-jquery-intellisense-over.html

Samples:
Get the input from a multiline text box/Textarea
var existingComments = $("[id*='txtComments']").val();
Explaination - txt comments is an text box namely: asp:TextBox runat="server" ID="txtCommentsAmend" TextMode="MultiLine".  val() gets the inner html/content.
Append additional data to the text box
$("[id*='txtCommentsAmend']").html(existingComments + 'more info');
Explaination - using the previous example variable append additional text in the textbox.

Saturday 2 October 2010

Powershell to Move a Site Collection to a new Content Database

Problem: I have several site collections inside a single content database.  The content database is growing rapidly.  Backup and restore is fairly slow and SQL can start slowing down if the db is large enough.

Hypothesis: Create at least additional content db, move specific site collections to the new Content database.  I was surprised that moving site collections to content databases is not in the Central Admin (CA) UI.

Resolution: Create an additional content database either using PowerShell (PS) or the UI namely:
1.> CA > Application Management > Manage Content Databases > Add a Content Database (I called my content database "WSS_Content_Empty").
2.> Move the Site collection to the new content database using PS
3.> Check the database has been moved in CA

More Info:
http://technet.microsoft.com/en-us/library/cc825328.aspx

Set New Content Database using CA Only:
  1. UI only option to achieve the same result would be to create the new content database using CA as shown above. 
  2. Next using CA go to "Manage Content Databases", select the old/existing content database and set it to offline (This means that you can't add new content databases, existing site collections are still available).
  3. Adding a new Site Collection will now use the new/next content database that is ready/online.   
End of Post

Backup and Restore Powershell commands:
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
cls
Backup-SPSite -Identity 'http://my.demo.dev/sites/kbtest' -Path C:\Projects\Backup\test.bak -Force -NoSiteLock -UseSqlSnapshot -Verbose
Restore-SPSite -Identity 'http://my.demo.dev/sites/newkbtest' -Path C:\Projects\Backup\test.bak -Force -Verbose 

Friday 1 October 2010

Save site as template link missing in site settings

Problem: You want to create an WSP for your site however, the "Save site as template" link is missing from the "Site Settings" page as shown below.
Hypothesis: Deactivate the Publishing features namely: Manage Site features > Sharepoint Server Publishing & Site Collection features > SharePoint Server Publishing Infrastructure.   You know have the ability to create site templates i.e. wsp files.  The problem is you don't have your publishing infrastructure.

Resolution: If publishing is enabled on your site, craft a url so you can create the wsp file.  Url is http://demo/_layouts/savetmpl.aspx

Tip:  You can only include up to 50 MB of contentin SP2010

SP2010 Connections Conference in The Hague - Day 2

Managed Meta data in custom solutions by AC was a real eye opener.  Managed Metadata Service (MMS) is very powerful and i need to be using it to a much greater degree.  AC's earlier talk on WCM was interesting but not a technical discussion but we were warned so not AC's fault. 

Mirjam van Olst gave a presentation on Logging, Monitoring & throttling.  It's the 1st time I've been to 1 of her presentations and I was hugely impressed she really knows her stuff.

Dan Holme gave a good session on Information Architecture (IA) and the MMS.  Useful as after AC's session i decided i definatelty needed more MMS info.

The last session I went to Wouter van Vugt's session on Access Services - Access services could potentially be huge in SP2010 and it was good to see a techy like Wouter highlight what it was good and bad at.

Generally a good day and a good conference.  Not exactly Vegas 2009 or even Berlin 2007 in quality but worth the trip and met some nice people that are really passionate about SharePoint.