Sunday, 22 January 2012

Sandbox solution ULS logging

Overview: Step-by-step instructions to create a logging module for Sandbox solutions using a full trus proxy that logs to the ULS.

1.> Ensure Sandbox solutions service is running:

1.1.> If the "Microsoft SharePoint Foundation Sandboxed Code Service" is stopped start it either thru CA (shown above or PS). 
PS> Start-Service -Name SPUserCodeV4

1.2.> Ensure the Windows service is running.

2.> Create project to test the full trust ULS logging proxy.
2.1> Create a Visual Studio project that deploys as a sandbox solution (test rig)

2.2.> Create a visual web part for sandboxed solutions (VSIX/Extension maneger: Visual Studion 2010 SharePoint Power Tools)

Note:  The submit button does not perform any action as the Full Trust Proxy must be created and deployed so we can use it to log code to the ULS.

3.> Create a ful trust proxy that code in the sandbox solution can call to add the error message to the ULS logs.

3.1.> Create an empty SharePoint project using Visual Studio 2010that deploys to the farm.
3.2.> CKSDev (VSIX extension has a SPI template to create a full trust proxy).  I used the SPI to create my ful trust proxy.
3.3.> Create the code to log to the ULS

3.4.> Edit the full trust proxy to use the ULS logging code created above.
4.> Add the proxy code call to the test rig/proxy caller i.e. sandboxed solution code.

Tip: Resart the Sandbox solution work process after each deployment

Tip: Use Powershell to check a correlation Id quickly:
PS>Get-SPLogEvent | ?{$_.Correlation -eq ""} | ft Category, Message -Autosize


Tuesday, 10 January 2012

Migrate MOSS site collection to SP2010

Problem: A common upgrade scenario I get in the role as a solutions architect is to move a site collection from a MOSS site to SP2010.
Initial Hypothesis: Do a side-by-side upgrade. Leave the existing site collection (or lock) it until the upgrade has the site collection on the new infrastructure. Don't go straight to production and I recommend doing the full upgrade on a standalone VM dev machine before even getting to test or production; this ensure the process works, is test and is repeatable.

Resolution: My suggested approach is to backup the content database containing the site collection, perform a “preupgradecheck and migrate it onto SP2010 on a dev machine. Next perform a backup of the site collection using CA or PS> as shown here Create the Installation Plan document that deploys the wsp’s and restore the site collection.  You can now move where the site collection to an existing content database.

More Info:

Tuesday, 3 January 2012

Migrate lists between environments

Problem: A client has been entering list data in your QA environement and wants the data migrated into production.

1) Migrate the list using a list template.  Navigate to the list > Under List tools select List > List Settings > Save list as template.

Limitations is lookup columns & high numbers of rows.
2) Export to access and import into the new environment.
Limitation is that history is lost, created by and modified bu are also lost.
3) Bakup a list using CA or Powershell and restore the list, the restore will need to be done using PoweShell (there is no UI in CA).
4) Use a migration tool such as Metalogix, MetaVis, Quest, Tzunami, AveDoc from AvePoint, Idera.  Personally I like Metalogix for SharePoint migration.  The AvePoint tool is good and Quest I can vouch for for migrations.  I believe all the tools are pretty good. 
5) Chris O'brien's Content Deployment Wizard -

Monday, 2 January 2012

Deploying Code on a SharePoint farm

Problem:  On large farms you may want to restrict code access to different levels, SharePoint 2010 offers 3 options as opposed to MOSS offering 2 options: GAC & Bin.

Initial Hypothesis:  Custom code can go into 3 places in SP2010:
1) GAC (easiest)
2) Bin
3) Sandbox 

GAC is the most open but you may want to restrict what code an do and where it can run.  In 2010 sandbox solutions or bin deployments are more restricted.  Sandbox solutions are way more restricted programatically then bin deployment but they are safer, also note that sandboxes can slow your farm down until the offending solution is expired for the day by SP2010.

Tip: Some code won't work in the bin such as workflows.  Seperate the code so if you are using the bin it goes into the bin and workflows and item events are added to the GAC, ensure you use dll versioning in the GAC (note: Workflows in progress will fail if you simply upgrade the dll in the GAC).

Tip: Include a referenced dll in your wsp deployment:

More Info:

Restoring dev machine nightmare

Problem: I have a been battling for days with my User Profile service, somewhere along the line it got corrupted with a CU. 

Hypothesis: I tried permissions, restarting the service, re-provisioning the service, nothing seemed to fix the issue.  Ultimately, I rolled back my VM to a clean install and used Spencer Harbar's guide after installing the August (re-issued) CU 2011.  This fix my User profile service.  Just extremely glad this is a dev machine.  Technet has an good article also on setting up the UPS.
Lastly I'm needed to redeploy all my custom code and restore the site collections to get me data.  The site collections have been transferred using backups can be done thru: 1) CA or 2) PowerShell
Restore the site collection using PowerShell PS> Restore-SPSite -Identity -Path "C:\Users\Administrator\Desktop\KB\kbsitecollection.bak" -force
More Info:

PS to backup a Site Collection:
Backup-SPSite -Identity -Path [-Force] [-NoSiteLock] [-UseSqlSnapshot] [-Verbose]
PS> Backup-SPSite -Identity -Path c:\\backup\SCbackup.bak -force -ea Stop

Note: You can't backup and restore a site collection to the same content database.  If you are using the same web application to restore the site collection, add another content database.

Note: You can only have 1 site collection restored per content database.  I restored a site collection, deleted it as I wanted it with a different name and could not restore.  When I perform the restore using PS I get the gollowing error: "Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully. No content databases in the web application were available to store your site collection. The existing content databases may have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain a copy of this site collection. Create another content database for the Web application and then try the operation again."

Repair the orphaned items for the offending content database:
PS> $cdb = Get-SPContentDatabase "ContentDB_Portal"
PS> $cdb.Repair($true)
PS> $cdb.Update()

More Info:
Take control of the restored content database