Wednesday, March 6, 2013

SharePoint Excel Services Application Error - Compatibility Range mismatch between the Web server and database

I recently worked on upgrading a 2010 content database to 2013, and once the upgrade had completed, I wanted to test the Excel Services Viewing Application.  I was quickly greeted with the "cannot load workbook" error message and began digging in ULS.  Here is the error message I found:

"Failed to load 'http://URL/book.xlsx' with error: 'Unable to open workbook due to unexpected exception: Microsoft.Office.Excel.Server.Host.HostFileException ---> Microsoft.SharePoint.Upgrade.SPUpgradeCompatibilityException: There is a compatibility range mismatch between the Web server and database "SharePoint_Content_SalesPortal", and connections to the data have been blocked to due to this incompatibility. This can happen when a content database has not been upgraded to be within the compatibility range of the Web server, or if the database has been upgraded to a higher level than the web server. The Web server and the database must be upgraded to the same version and build level to return to compatibility range."
I didn't dig into the specifics of WHY this error occurred, but I definitely remember running into security issues when installing Office Web Apps in 2010, and sure enough this error message turned out to be a security problem.  I granted proper security access to the Service Account used by the Excel Service Application using powershell and fixed the issue.  The powershell I used can be found below:

$webApp = Get-SPWebApplication http://webappurl
$webApp.GrantAccessToProcessIdentity("domain\username")

Hope this helps someone out there!

Monday, November 5, 2012

Setting "In the top-level folder" Programatically

 
Spent some time today trying to figure out how to set the "In the top-level folder" option for a SharePoint view via powershell.  Below is how the screen looks  from the editor:



I dug through the JavaScript on the ViewEdit.aspx page and found that the value is set using a built in ContentTypeID for RootOfList content type.  Here is the powershell snippet I used to update the value:


Hope this helps someone out there!

Thursday, April 7, 2011

Overriding Top Navigation Menu for SharePoint System Pages

I just had a request from a client to have the same navigation everywhere in a site collection including system layouts pages (settings.aspx, mngfield.aspx, etc...). I had a custom masterpage which used a custom navigation provider, but the system pages in the layouts directory never picked up the custom provider data.

I took a look at the settings.aspx page to figure out why/how the SiteMapDataSource was being overridden, and sure enough the TopNavBar.asxc controltemplate is being loaded:


Next, I check out the TopNavBar.ascx (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES) to figure out what was going on. You'll see in the image below that the TopNavBar.ascx is overriding the topNavigationDelegate control and using SPNavigationProvider instead of the custom provider defined in my masterpage.


Having figured that out, the next step was simply to override the delegate control using a control element in a feature. After deploying and activating the feature, the various layouts pages had the correct navigation item.


IMPORTANT NOTE:
Make sure to test which navigation menus are affected by the feature. The number of places affected (site, subsite, site collection, web application, Farm) will vary depending on how you scope the feature (Farm, Site, Web, etc...)


Tuesday, December 28, 2010

Check In SharePoint Documents using Powershell while Preserving "Modified" and "Modified By" MetaData

The Problem:

I was recently handed the following tasks:
  1. Checkin thousands of recently migrated documents

  2. maintain modified by metadata

  3. maintain modified date metadata

  4. must be done in powershell
The Solution:

I did some research and found a good post describing how to preserve the modifed by data here, but I still had to find a way to get it into powershell and also address the "modified date" requirement.

Below is the powershell I came up with that is working for me. You will probably want to update the list query piece to ensure the correct items are retreived. Also, I'm not quite sure the "RunWithElevatedPriveleges" is required or not, so you can test that out as well.

Hopefully this helps someone out there!

#function to return bindings to use in GetMethod() function
function Bindings()
{
return [System.Reflection.BindingFlags]::CreateInstance -bor
[System.Reflection.BindingFlags]::GetField -bor
[System.Reflection.BindingFlags]::Instance -bor
[System.Reflection.BindingFlags]::NonPublic
}

#Function to checkin a file using a specific user
function CheckInFileByUser([Microsoft.SharePoint.SPFile]$file, [string]$comment, [Microsoft.SharePoint.SPCheckinType]$checkInType, [Microsoft.SharePoint.SPUser]$user)
{
$bindings = Bindings
[System.Type[]] $types = [string],[Microsoft.SharePoint.SPCheckinType],[bool], [Microsoft.SharePoint.SPUser]
$method = $file.GetType().GetMethod("CheckIn",$bindings,$null,$types,$null)
$params = $comment,$checkInType,$false,$user
$method.Invoke($file,$params)
}

#Main code section
$baseUrl = "http://localhost/sites/records"
$listName = "Record Library"

Clear-Host
$site = Get-SPSite $baseUrl
$web = $site.OpenWeb($site.RootWeb.ID)
$list = $web.Lists[$listName]

#example only, get items using view or query of your choice
Foreach($item in $list.Items)
{
$file = $item.File
if($file.Level -eq [Microsoft.SharePoint.SPFileLevel]::Checkout)
{
#get the current date to use later
[System.DateTime]$date = $item["Modified"]
[Microsoft.SharePoint.SPFile]$file = $item.File

#get the current editor SPUser to use when checking in the file
$user = New-Object microsoft.SharePoint.SPFieldUserValue($web, $item["Editor"])

#check in the file
CheckInFileByUser $file "My Comment" "MajorCheckIn" $user.User
#change the modified date back to the original value
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
{
$item = $list.Items.GetItemById($item.ID);
$item["Modified"] = $date
$item.Update()
} )
}
}

Thursday, October 21, 2010

Disable Ribbon Positioning System in SharePoint 2010

Ok, so I'm working on branding a SharePoint 2010 public facing internet site, and I just couldn't figure out how to disable the ribbon positioning system.

I started out using the steps provided in this article (I recommend reading this article if you are unsure of how the v4master page works with the ribbon positioning system), which are as follows:

1. Remove the "_fV4UI" variable from the top of the page
2.Remove or change the Workspace element's ID to make the ECMA Script code abord early during window resizes
3.Remove the "scroll=no" in the body tag
4. In your CSS file, remove or change the width, height, and overflow declarations ont he bady tag
5. Optionally, in your CSS file, remove the s-4 workspace and s4-bodycontainer rules since they are no longer necessary

So after going through these steps, the scrolling still did not work for me. I'm guessing I missed a step that was inferred in step 5, but here is what I added to my custom CSS file to get scrolling to work:

body.v4master{
height:100%;
width:100%;
overflow:auto;
}

Hopefully this helps someone out there!

Errors when Starting SharePoint User Code Service (aka Sandboxed Code) with Powershell

The Short:
The service account used to host the SharePoint User Code Service needs to be added to the Performance monitors group on the server running the service.

The Story:
Recently, I was working on installing some SharePoint 2010 Farms using powershell, and I kept seeing errors when starting the SharePoint User Code (aka Sandboxed Code) Service. After installing the farm, the SharePoint 2010 User Code Host windows service was stopped, and the following errors appeared in the event log:


- "The SharePoint 2010 User Code Host service terminated unexpectedly"

After looking through the ULS logs on the server, I noticed errors around calls to the performance counters on the machine. It turns out that the user account that is used for the User Code Service needs additional permissions on the machine running the service. Specifically, the account to be added to the Performance Monitor Users group.

The issue only appears to be an issue when starting the service from powershell specifically because when started from central administration, the user account defaults to the Farm account, and that account is automatically added to the correct group.

More error details can be found at http://support.microsoft.com/kb/983081/en-US, but the kb article does not specify the group required.

I hope this helps someone out there!