Tuesday, November 27, 2012

SharePoint 2010–Error Saving Site as Template with User Information List

When saving a site as a template, an error such as the one below may be displayed.  Viewing the ULS logs isn’t much help as it displays similar error information and also a NullReferenceException.  I had a similar error with a custom list and deleting all of its items resolved the error.  Since I was not saving data (Include Content checked), I knew that it wasn’t necessarily a data issue.  The root cause ended up being view throttling.  For some reason, the view throttles for a regular user were preventing large lists from being exported.  This error can be worked around by temporarily increasing the web application’s list view throttles.

 

Error exporting the list named "User Information List" at the URL: _catalogs/users

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.SharePoint.SPException: Error exporting the list named "User Information List" at the URL: _catalogs/users
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SPException: Error exporting the list named "User Information List" at the URL: _catalogs/users]
   Microsoft.SharePoint.SPSolutionExporter.ExportLists() +27271840
   Microsoft.SharePoint.SPSolutionExporter.GenerateSolutionFiles() +511
   Microsoft.SharePoint.SPSolutionExporter.ExportWebAsSolution() +27287522
   Microsoft.SharePoint.SPSolutionExporter.ExportWebToGallery(SPWeb web, String solutionFileName, String title, String description, ExportMode exportMode, Boolean includeContent, String workflowTemplateName, String destinationListUrl) +1789
   Microsoft.SharePoint.SPSolutionExporter.ExportWebToGallery(SPWeb web, String solutionFileName, String title, String description, ExportMode exportMode, Boolean includeContent) +44
   Microsoft.SharePoint.ApplicationPages.SaveAsTemplatePage.BtnSaveAsTemplate_Click(Object sender, EventArgs e) +331
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981


Version Information: Microsoft .NET Framework Version:2.0.50727.5466; ASP.NET Version:2.0.50727.5456

Wednesday, October 17, 2012

PowerShell: Current Script Folder (Call operator, dot source, and path)

There are a few ways to get the current directory of the executing PowerShell script, but the issue I ran into was that some of the ways changed based on how the script was called.  This was the PowerShell line I used previously and what works in the PowerShell ISE very well,

 

$scriptFolder = $myInvocation.InvocationName | Split-Path -parent

and this is the line I use now.

 

$scriptFolder = $myInvocation.MyCommand.Path | Split-Path -parent

 

The subtle difference in the usage of myInvocation is explained in detail in Kirk Munro’s deep dive on the topic, http://poshoholic.com/2008/03/18/powershell-deep-dive-using-myinvocation-and-invoke-expression-to-support-dot-sourcing-and-direct-invocation-in-shared-powershell-scripts/.  Basically, there are 3 ways you can call a PowerShell script using either the call operator (&), a dot source (.), or a path.  The first PowerShell line only works when using the full path.  This makes perfect sense after one realizes what the InvocationName property represents, but it was confusing at first.

Friday, August 17, 2012

PowerShell – SharePoint List Data to CAML Data

Here’s a handy PowerShell function that will convert an existing list instance’s data to a CAML data structure.  The output isn’t indented, but most editors like Visual Studio can do that for you.  This also doesn’t handle XML escape characters, but it would be simple enough to add if the data required it.

 

function ListDataToCamlData($webName, $listName, $fields){
    $newLine = [Environment]::NewLine
    $web = Get-SPWeb -Identity $webName
   
    $stringBuilder = New-Object -Type System.Text.StringBuilder
    $stringBuilder.Append("<Data><Rows>")
    #TODO - Handle XML escape values &amp; &quot; &lt; &gt; &apos;
    $web.Lists[$listName].Items | %{$stringBuilder.Append("<Row>"); foreach($field in $fields){$stringBuilder.AppendFormat("<Field Name=""{0}"">{1}</Field>", $field, $_.$field)}; $stringBuilder.AppendFormat("</Row>{0}", $newLine)}
    $stringBuilder.Append("</Rows></Data>")
   
    $web.Dispose()
   
    return $stringBuilder.ToString()
}

 

And here’s an example in calling it

 

ListDataToCamlData “http://www.somesite.local” "Announcements" @("ID", "Title")