Wednesday 25 August 2010

Creating SharePoint Lists declaratively using Visual Studio 2010

Problem: Create a custom list to hold configuration values in a list.
Resolution Overview: Using VS 2010 create a feature that deploys the new list with content.
1.> Create Site Columns/fields;
2.> Create the Content Type using the Site Columns;
3.> Create the List Definition from the Content Type; and
4.> Add items to the list instance elements.xml.

Resolution Steps:

1.> Create Site Columns by adding a new "Empty Element" item in VS.
Declaratively add the site column to the elements.xml file;
Ensure your element file has been added to a feature for deployment;
Deploy the feature and ensure the Site Column has been add using the UI "Site Setting" > "Site Columns";

2.> Create the Content Type using the Site Columns
Using VS 2010 create a new Content Type;
Add caption
Using the existing Site Column create the Content Type declaratively;
Check the Content Type is create after you have deployed; 

3.> Create the List Definition from the Content Type

Follow the wizard and select the newly created Content Type "Configuration";
Check the List definition has created the elements.xml and schema.xml files;

Edit the Schema.xml File to Show the new columns defined int he content type (otherwise you will only see the "Title" column);

4.> Add items to the list instance elements.xml

Ensure the List is created



Tip: The fields/site columns & FieldRefs used in the elements files can be added thru the VS2010 tools.  VS2010 > View > Toolbar
Tip: Updated 18 Oct 2010 - CKSDev has the functionality to import Site Columns, this is useful in that you may of created the SiteColumns via the UI on a prototype site and you can not easily get the xml to create the site columns/fields declaritively.  http://blog.mastykarz.nl/cksdev-support-importing-site-columns/

Sandbox solution deployment error

Problem: Deploying a solution package to a sandboxed site using Visual Studio 2010 I receive the error "Error occurred in deployment step 'Activate Features': Timeout occurred while running the SharePoint Sandboxed Code service. This service is required to run sandboxed solutions in SharePoint.  Please ensure the service is configured correctly in SharePoint.". 
Resolution: I restarted my "SharePoint 2010 User Code Host" Windows Service.


More: Common error after initial install of SharePoint Error: Cannot start service SPUserCodeV4


http://www.sharepointdevwiki.com/display/spadmin2010/Configuring+Sandboxed+Solutions+-+Cannot+start+service+SPUserCodeV4+on+computer

Friday 20 August 2010

SPMetal is throwing a ThreadAbortException

Problem: I am inserting new items into a list using Linq-to-sharepoint (SPMetal), my code throws a ThreadAbortException exception. 

Initial Hypothesis: When I run the code as a Site Collection Owner the new list item is inserted.  So this is a permissions issues.  I increase the permissions on the user that can't insert the list item.  It works so this is clearly a permissions issue.  After the user tries to perform the insert list item, they are directed to the "Error: Access Denied" message on the web page.  Clearly the error message is misleading however, SharePoint seems to understand the ThreadAbortException is a permissions issue.  The issue is the user does not have sufficient permissions to perform the action.  By elevating the user permissions the error goes away.  All well except the error logging is throwing an odd error, after some digging this issue has been blogged before however not for LINQ to SharePoint.

Resolution: Assign the correct permissions to the user performing an action.

Thursday 19 August 2010

SPMetal Invalid file name error

Problem: SPMetal fails with the following error:
Error: Invalid file name.
The file name you specified could not be used. It may be the name of an existing file or directory, or you may not have permission to access the file.

Initial Hypothesis: Permissions on the directory are wrong or the SPMetal proxy code file being created is locked.  Folder permissions haven't change and the file is removed from previous runs.  So my initial hypothesis is wrong.  Previously I was working on building lists created from custom content types and deployed via a feature.  There are 2 lists based on content types.  The list definition, custom content type & site columns have been removed.  The 2 lists still appear in my UI and when I click on the list I get an application NullReferenceException error.  Makes sense as SharePoint hasn't cleared up the list instances.
                            ============
Updated Problem: I have 2 lists on my SharePoint 2010 site that I can see in the web UI and through my Visual Studio Server Explorer however, I can't get into the UI as I am getting the NullReferenceException error.  I need to remove the lists to allow SPMetal to work.

Initial Hypothesis: Use another tool to delete the list, VS solution explorer won't let me update the list.  Use SharePoint Designer, on opening SPD it won't show me any lists or libraries.  So I'm left with using an stsadm cmd or Power Shell.  As I am loving PowerGui I went for the Power Shell Solution.
Resolution: Open the SharePoint Power Shell window, delete the lists using the following code:
$url = "http://demo1"
$site=new-object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()
$list = $web.Lists["Customers"]
$list.Delete()
Now SPD works, SPMetal works - Problem resolved.
Summary: I created lists from content types, I removed the content types, list definitions however I left the list instance.  This cause SPD, SPMetal to err.  Cleaning the defunct lists using Power Shell corrects the issues.
More Info:
PowerGui sharePoint CheatSheet

Monday 16 August 2010

Using PowerShell to retrieve SharePoint site column guids

Problem: I am creating a Content Type that uses 1 of the built in site columns (field column), I need the guid of a OOTB site column.  I am looking to use the OOTB "Append-Only Comments" site column.
Resolution: Open PowerShell and execute the cmd:
$web = Get-SPweb http://demo1
write-host $web.Fields["Append-Only Comments"].Id

Tip: Don't add xml comments into declaritive content type creation, it stops the activation without any warning. 

SharePoint 2010 Error occurred in deployment of step ‘Activate Features’: the field with ID defined in feature was found in the current site collection or in a sub site.

Problem: I can't redeploy Site columns using Visual studio 2010 to an SP2010 site collection.  I get the error "Error occurred in deployment of step ‘Activate Features’: the field with ID defined in feature was found in the current site collection or in a sub site".
Resolution: Retract wsp, restart VS2010, open the project and deploy the solution.  VS2010 is caching data.
Microsoft kb

Friday 13 August 2010

SharePoint 2010 Software Licencing

Rough idea of pricing excluding VAT.  This is not from Microsoft and pricing is not fixed as I have laid it out in this post.  Saying that, please consult a licencing expert most resellers such as HP have licencing experts to help you, this is merely a guide to help you get started.  Without further procrastination ...
Windows 2008 & SharePoint is priced on a per server basis.  SQL is charged at a per processor licence.  Software assurance is about and additional 28-30/year.
  • Windows 2008 R2 standard x64 - £2,5k
  • SharePoint Std Internet - 5,5K ?
  • SharePoint Ent Internet - 20K ?
  • SharePoint Std Internal - 3K ?
  • SharePoint Ent Internal - ?
  • SharePoint Std CAL £45/cal
  • SharePoint Ent CAL £80/cal
  • SQL 2008 R2 Std/proc £3,5k
  • SQL 2008 R2 Ent/Proc £14k
Software Assurance: MS sell software assurance, this entitles you to upgrade over the period of the SA agreement charged at about 30% per year. If the new version of the product is due for release and you will move to the new version in the next year or 2, Software assurance may be a good option. However as SP2010 has just been re4lease and SharePoint 15 is due some time in 2014, the cost of SA for that period would be more than buying the SP15 software (assuming prices stay the same). It is a per circumstances decision but I would opt to buy the SP2010 without SA, in 2014 buy new licences and the cost will most likely be lower for the upgrade and it will allow for a in-place upgrade (I.e. SP2010 and SP2014 would run next to each other until everything is upgraded). I would personally prefer to do the upgrade as it will keep the systems cleaner, have better performance and allow for a safer upgrade. Also not you can use Enterprise agreements and stop paying SA but the key if to look at minimising the cost of SharePoint licences over a 5 or 6 year period.

Tip: Licencing prices change depending on factors such as volume discounts, types of licences, software assurance, are you a charity, are you buying or renting licences.  This post takes a simplistic view of SharePoint licencing and is not Microsoft's policy but merely to help mine the licencing minefield that faces most big software projects.  Please consult a licencing expert, it will save you time and money.
Tip: Windows External Connector licences for Windows 2008 (Needed for SharePoint 2010 Internet licences if the external users will use any file or print functionality provided by Windows)
More Info:
Microsoft's SharePoint Licencing
Development Platform Stack (SharePoint versions for developers)
Update: 15 Nov 2010 - Microsoft SharePoint 2010 for Internet explained A good document explaining mix of Internet and Intranet usage
SharePoint 2010 version comparisons
 Licencing explained -
Ari's blog - licencing
http://stovereffect.com/2010/07/03/sharepoint-2010-licensing-part-v-sharepoint-2010-licensing-costs/
Lync licencing - Office Communicator 2007 R2 upgrade
Developer & UAT licences would be covered by MSDN/technet subscriptions.  Technet does not include Visual Studio 2010.

VS2010 & TFS licencing

   ========
Example to explain licencing
Scenario:
We have 700 internal users with AD accounts.  We have 15 external suppliers with a total of 2000 users that access our SP2010 system.  We have a dedicated physical SQL Server 2008 R2 std edition and 2 SharePoint NLB Windows 2008R2 std edition web servers.  What licences do we need? 
Assumptions:
Prices are my estimated guess.
Software assurance (SA) is not selected, simply multiply by 1.6 for a rough figure.
Resolution:
3 Windows 2008 R2 licences for the SQL box and 2 web servers.  +-£7K
SQL Server licences charged at per CPU.  4CPUs for +-£14K
SP2010 Std edition licences for the 700 internal users at £3K/server for 2 servers +- £6K
SP2010 Std edition licences for the external/Internet licence users at £5,5K/server for 2 servers +- £11K
700 Std user SP2010 cal's @£45/user  +- £31,5K
Total Software estimate:  £69.5K
Note: As you can see you have to pay for 4 server licences on 2 servers.  Those astute people out there may realise that you could add 2 more SP 2010 servers to your farm without paying for and more SP licences.  Only think is you need to then only allow internal access on the Internal servers and Internet access to the external SP server.

Development Licences
Technet covers all development licences you will need with the exception of Visual Studio.  MSDN licencing includes Visual Studio 2010.  Visual Studio Ultimate, & Professinal can be purchase individually or through MSDN.
TFS 2010 (Team Foundation Server) has 3 ways to get licences:
  • MSDN - individual all versions get 1 instance licence & 1 Cal with a MSDN subscription.
  • Volume licencing – each person accessing TFS server needs a Cal.
  • Retails – Organisation gets 1 instance of TFS & 5 Cal’s. Approx £500.
Any TFS instance needs SQL 2008 standard edition, this is included in the TFS licence.  Can't use this free version of SQL Server for anything else.

Update 8 Mar 2011: Ari Bakker Post of Web Parts by SP licence Type
Update 10 Nov 2011: Technet

More Info:
http://stovereffect.com/2010/07/01/sharepoint-2010-licensing-part-iii-search-office-web-applications-and-project-server/
http://www.directionsonmicrosoft.com/microsoft-licensing/30-licensing/1458-sharepoint-server-2010-licensing.html