Tuesday 31 August 2010

SharePoint 2010 Prerequisite Installation

Problem: SP 2010 has to have prerequisites run that setups and installs software components.  This can be run by clicking the prerequisiteInstaller.exe or via a cmd prompt.  The cmd prompt option is useful for unattended installs.  Additionally the prerequisite installer will access the internet to download the required files, my environment does not have Internet access.

Initial Hypothesis: Download software onto the WFE servers and run the prerequisites to use local copies of the software that is required.

Resolution:
  • Extract SP2010 onto the local WFE
  • Open the PrerequisiteInstallerFiles folder and copy msi's & exe's (Minimal files would be: sqlncli.msi, mschart.exe, dotnetfx35setup.exe, Syncronisation.msi, FilterPack64bit.exe, SQLServer2008_ASADOMB10.msi)
  • Open a cmd prompt and run as an Administrator.
  • Navigate to the appropriate directory using Windows explorer where PrerequisiteInstaller.exe is and create the file PrerequisiteInstaller.Arguements.txt
  • Edit the PrerequisiteInstaller.Arguements.txt file as shown below.  Save and close the files.
  • Navigate to the appropriate directory using the cmd prompt where PrerequisiteInstaller.exe is located and run the cmd "PrerequisiteInstaller.exe".  Mine is c:\Software\SP2010>PrerequisiteInstaller.exe

Tip: The Prerequisiteinstaller.Arguements.txt must not have line breaks between switch statements only spaces.  I.e. the config must be on 1 line.

PrerequisiteInstallerArguements.txt:
/unattended /SQLNCli:PrerequisiteInstallerFiles\sqlncli.msi /ChartControl:PrerequisiteInstallerFiles\MSChart.exe /NETFX35SP1:PrerequisiteInstallerFiles\dotnetfx35setup.exe /Sync:PrerequisiteInstallerFiles\Synchronization.msi /FilterPack:PrerequisiteInstallerFiles\FilterPack64bit.exe /ADOMD:PrerequisiteInstallerFiles\SQLSERVER2008_ASADOMD10.msi

More Info:
Create an "offline" SP2010 prerequisite installer
Prerequisite cmd config options
Pre-requisite software lists
SP2010 install cmd-line args


Monday 30 August 2010

Linq to SharePoint 2010 DSL extensions

I have been building a composite application for a client that has a heavy reliance on SPMetal.  There are several issues using SPMetal and I have spent time this weekend trying to figure out how SPMetal works so I could work around our issues.  I found this project from MS LINQ to SharePoint DSL extensions.  Pretty impressive tool.

A few years back I went to Microsoft to hear about Domain Specific Languages (DSL), at the time I thought it was pretty amazing but couldn't see any benefit for me and thought it was going to be pretty niche in fields like academic research.  I was wrong and this project is definitely worth a look it you are going to use SPMetal, you may not need or want the extra ability but pretty useful.  Olivier Carpentier has written a good user guide & made a pod cast to go along with the unsupported MS project.

Thursday 26 August 2010

Creating lookup columns and list declaratively in SP2010

Problem: When creating lists via a feature, you may want to link SharePoint 2010 lists.
Initial Hypothesis: In MOSS to link to SharePoint 2007 lists you had to do it via the UI or via a deployable feature.  The list was created declaratively using XML (CAML).   Lastly the lookup column needed to be created using a feature receiver.  As in MOSS, in SP2010 you can create a lookup column using the UI but this is not a reusable deployment method and falls prey to errors.  SP2010 allows you to create lookup lists using declarative CAML.

Resolution: Create the lists, add site columns (fields), then add the site columns to a content type and lastly generate the list definition & list instance.  Steps are detailed below:
  • In an elements file declaratively create a lookup column that uses the specified list as shown below: 

  • Add the new lookup column to a content type:
  • Your existing/create a list definition that derives from your content type.
Note: The Lookup Site column needs to specify the list it is looking up when you declare the XML.
More Info:
Creating lists declaritively in SP2010 - Post outlines creating SharePoint lists, coupled with this post you can create lists that are related using a feature to create your lists.
Available field types

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