Friday 13 August 2010

SharePoint 2010 console application System.IO.FileNotFound error

Problem: Built a local console app to access a SharePoint site, add System.Web & Microsoft.SharePoint references to the console project.  Run the code and get a System.IO.FileNotFound error.
Code SPSite site = new SPSite(http://demo1);
Hypothesis: Check url is correct (it was).  VS2010 console apps are set to be x86 by default.  SharEPoint only works on x64 so Microsoft.SharePoint is x64. 
Resolution:  Open VS2010, right click the console project.  "Properties" > "Build" tab, set "Platform target to "x64".
Tip: Uses the .NET 3.5 for console applications.
More info:  Top 2 search on Google yielded the solution.  Console FileNotFound error. and 2nd solution System.IO.FileNotFound Error

Wednesday 11 August 2010

Feature Receiver for dispaying Publishing Images as html in a document library

Problem: Publishing images can't be created on a document library however, using a site columns you can add Publishing Images & Publishing Html.  However the Fields don't display properly unless you create the content type from the site columns and lastly generate the document library from the content type.  I already have data so I need the existing columns to display as a custom list publishing image would work.

Resolution: Create a feature receiver to change the column properties pragmatically.  There is a catch in that this only applies if you haven't created the document library off the content type which in turn was created off the site columns.  Anyway, attached is a feature receiver scoped at web level look at the customised document library and make the publishing field rich text compliant.  

SharePoint 2010 feature receiver not working

Problem: Feature receiver is not firing.
Hypothesis: It's hard to debug feature receivers but it can be setup, however my feature receiver was never getting called.  Implemntation via VS2010 must be wrong.
Resolution: I created a new feature and added a feature receiver, this was working.  The screen shot below shows the differnce in my features that was cause when I renamed the feature.

Number of Accounts needed for SP2010 & Managed service accounts

Problem: How many accounts are required for SharePoint 2010?
Hypothesis: In MOSS I used 7 accounts for farm installs using my default slip-steamed medium/large farm install.  It really depended on what you needed to run.  You can use service accounts to run services in SP2010.
Resolution: SP2010 introduces managed service accounts, that are used for running SharePoint services.  You don't need to know password and it changes the account passwords per your SharePoint policy so a better option in my opinion so I have used them on my 2 installs.  Also pretty nice to only require the 3 accounts for install as shown below:
http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/a740e3ee-6f2d-473e-a63b-d97e52513754
http://technet.microsoft.com/en-us/library/ee662513(office.14).aspx

Summary:
Need AD accounts
  1. Administrator account (Admin on local SP boxes, needs domain user account permissions, pref db owner
  2. Farm service account/database access account (needs domain user account permissions)
  3. Microsoft SharePoint Foundation 2010 search service account (needs domain user account permissions)

Tuesday 10 August 2010

Reusable content in SP2010 issue

Problem:
1.> Reusable content is added to an html field control as shown below

2.> Under the "Reusable Content" inserted into the page inside the same field contrl, add any OOTB web part.
3.> When you save or publish the page, the html gets mixed around and displays incorectly.

Hypothesis: I have to think this is a bug as each item can be added individually.
Possible Resolution:
  • Use different page layouts with more field controls or
  • programatically retrieve the reusable content and display it or
  • Use a dataview WP with custom xslt to display the reusable content.
Tip: Reusable content is not available inside web parts. So like in MOSS, you cannot insert reusable content inside the OOTB content editor web part. Reusable content is only available in field controls.
Tip: Reusable content is similar to what it was in MOSS, it is available if the SharePoint Server Publishing feature is activated in both the "Site Collection Features" & "Manage Site Features".

Additional infoSerge Luca confirmed this issue.

Thursday 5 August 2010

Retrieving Publishing Columns using a CAML Query

Overview: LINQ is easy and strongly type however, occasionally we need to get data in an optimised fashion or LINQ won't do the job i.e. inefficient queries, Publishing fields and we need to revert to a CAML query.

Code Example:

Explanation:
  1. Perform a CAML query, U2U still works on SP2010 and I use it to work out my CAML query.
  2. Add code that performs the query, optimise it (you don't need every field returned by CAML, you can look at the query results without the "ViewFieldOnly" & "IncludeMadatoryFields" setting and you will see how many fields are returned which for big queries isn't good).
  3. Using the SPListItem retrieve the field data from the publishing fields.
Andrew Connell explains how to extend SPMetal
Tobias Zimmergrin's blog has good Linq to SharePoint 2010 info, his blog on showing the CAML generated by LINQ to SharePoint queries is invaluable to work out what SPMetal is generating.
Update: 09/10/2010 Extend SPMetal to retrieve list attachments

Update 27/10/2010 - A re-hash of Tobias Zimmergrin's blog describing retrieving the CAML generated by a LINQ to sharePoint Query.