Support for Rewrites and Redirects on SharePoint

If you use Microsoft SharePoint versions 2007, 2010 or 2013 and also use URL Rewriting techniques, you should review this Microsoft Knowledge Base article:

Supportability of Rewrite and Redirects with SharePoint 2007/2010/2013

According to the article, if you change the path of the URL (the part after the domain, e.g. /pages/home.aspx) received by IIS and send a different one to SharePoint (called asymmetrical URL rewriting in the article) you are unsupported.

If you send the same path of the URL received by IIS to SharePoint, then you run a supported scenario.

 

Why is it important? – you might ask.

It is important because when you run into issues on your implementation and you don’t find a good solution “googling” around, you might have to call Microsoft for support and their answer for you might be: “you’re running an unsupported scenario.”.

In my case, we ran into issues with AXD files not being sent to the browser by SharePoint and the issue looks to be related to both the URL rewriting and the output cache. for now we disabled the output cache as a workaround and it seems to working fine. Let’s see if we can find a good solution for this issue. I’ll probably write more about it here when we figure it out.

If you use any type of URL rewriting on SharePoint or are planning on doing it, you should this article out.

 

See you,

Amadeu.

 

 

Showing/Hiding the Ribbon Based on Permissions

I’ve got a task to check why the ribbon was not being displayed for a user with full control on a page on a SharePoint 2010 Publishing site.

Requirements-wise the request made total sense: the user with full control permissions on a page should be able to see the ribbon, check the page out, edit the page, check it back in and publish it. During my tests I noticed the master page had a SPSecurityTrimmedControl control around the ribbon. This control was preventing to ribbon to be shown for the user because it was configure to only show it for users with ManageWeb permissions.

<SharePoint:SPSecurityTrimmedControl
ID=”TrimRibbon”
PermissionsString=”ManageWeb”
runat=”server”>

Checking the list of SPBasePermissions values for the PermissionString property I was able to find the permission I wanted to use: EditListItems. This way all users with permissions to edit items/pages can see the ribbon.

When I changed the SPSecurityTrimmedControl control to use the EditListItems permission and published the master page, the user was still not seeing the ribbon.

After a couple of tests using different permissions, I found an article by Infowise explaining  the details of the SPSecurityTrimmedControl control and the usage of the PermissionContext property. This property controls the scope of the PermissionString property and by default is uses CurrentSite. Some of the values of the SPBasePermissions are scoped to the List or List Item.

In order to my permission check to work, I had to add the PermissionString property to the SPSecurityTrimmedControl control using the CurrentItem value:

<SharePoint:SPSecurityTrimmedControl
ID=”TrimRibbon”
PermissionsString=”EditListItems”
PermissionString=”CurrentItem”
runat=”server”>

After this change, the user was able to see the ribbon on the pages he had full control permission on and the site admins are still able to see it.

 

During my research, I also found this other article explaining a little bit more of the SPSecurityTrimmedControl control. Worth to check it out.

 

 

See you,

Amadeu.

 

Retrieve a List of All Items Checked Out in a Site using Powershell

Hi there!

This is a scripts to list files which are currently checked out on a site collection. Some times users check files out and forget to check them back in. It was based on a script found at http://www.thorntontechnical.com/tech/powershell-tech/powershell-tip-find-all-checked-out-files.

$webAppURL = "http://yourwebapplication.com" 

function ReportCheckedOutItems() {
	$webapp = Get-SPWebApplication $webAppURL

	foreach ($site in $webapp.Sites) 
	{
		write-host "Site Collection: $($site.Url)"
		$allwebs = $site.allwebs
		foreach($web in $allwebs)
		{
			$count = 0
			write-host "--Site: $($web.Url)"
			foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {
				Write-Host "-----List: $($list.RootFolder.ServerRelativeUrl)..."
				foreach ($item in $list.CheckedOutFiles) 
				{
					if (!$item.Url.EndsWith(".aspx")) 
					{ 
						continue 
					}
					write-host "File: $($item.Url) - checked out by $($item.CheckedOutBy)" -ForeGroundColor Red
					$count++
				}
				foreach ($item in $list.Items) 
				{
					if ($item.File.CheckOutStatus -ne "None") 
					{
						if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null) 
						{ 
							continue 
						}
						write-host "File: $($item.Url) - checked out by $($item.CheckedOutBy)" -ForeGroundColor Red
						$count++
					}
				}
			}
			if ($count -gt 0)
			{
				write-host "Found $count checked out files for site $web" -ForeGroundColor Red
			}
		}
	}
}

ReportCheckedOutItems

 

You can download the script file here

I hope it is useful for you as it is for me.

 

See you,

Amadeu.

Permissions to Administer SharePoint 2010

I’ve been reading some articles on how to set a user up as a SharePoint Administrator and noticed there is no consensus on which should be the steps to achieve it.

In our environment we follow these steps:

  • Add as local admin to the servers on the farm
  • Add to the farm administrators group
  • Add as powershell admin using the command: add-spshelladmin -username domain\user
  • Add user as DB_OWNER to the Config and to the content databases

See you,

Amadeu.

SharePoint 2010 Error Creating Sub-Sites: Unexpected error in Silverlight Application

If you see an “unexpected error in Silverlight application” error message when trying to create new sub-sites or other items on a SharePoint 2010 you need to check the web page security validation on your web application. Probably it is set to Off.

 

To change it:

  • Go to Central Administration.
  • Go to Application Management > Manage Web Applications.
  • Select the web application with the issue and click General Settings on the ribbon.
  • Change the Web Page Security Validation from Off to On.
  • Click OK to close the dialog.

Test the sub-site creation and the Silverlight should work just fine.

 

See you,

Amadeu.

Powershell Script to Change Page Layout on Publishing Pages

This is an useful script to change the Page Layout for all the publishing pages for a site.

$spWeb = Get-SPWeb("http://yourwebapplication.com/yoursite")
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($spWeb.Site);

$siteLayouts = $pSite.GetPageLayouts($false)
$myLayout = $siteLayouts["/_catalogs/masterpage/yourpagelayout.aspx"]
#$myLayout
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='RecursiveAll'"

$pages = $pWeb.GetPublishingPages($query)

foreach ($page in $pages)
{
	if ($page.ContentType.Name -eq "Folder")
	{
		continue
	}

	$page.Layout = $myLayout
	$page.update()
	$page.ListItem.File.Publish("")
	$page.ListItem.File.Approve("")
}
$spWeb.Dispose()

Get the script file here.

Have fun!!!

See you,

Amadeu.

Set Access Request Email on All Sub-Site of a Web Application

Hi all!

Follow a Powershell script to change the Access Request email for all sites in a we b application:

$webapp = Get-SPWebApplication "http://yourwebapplication.com"
$currentEmail = "current.email@company.com";
$newEmail = "new.email@company.com";

foreach($site in $webapp.Sites)
{
   foreach($web in $site.AllWebs)
   {
     $url = $web.url
	 Write-host $url
     if (!$web.HasUniquePerm)
     {
            Write-Host "Access Request Settings is inherted from parent."
     }
       elseif($web.RequestAccessEnabled)
       {
			Write-Host "Access Request Settings is enabled."
			write-host $web.RequestAccessEmail
	        if ($web.RequestAccessEmail -eq $currentEmail)
			{
				Write-Host "Email needs to be updated."
				$web.RequestAccessEmail = $newEmail
				$web.Update()
				Write-Host "Email changed successfully!"
			}

       }
       else
      {
            Write-Host "Access Request Settings not enabled."
      }
   }
}

 

Hope this helps you!

 

See you,
Amadeu.

Removing a Web Part from Pages Using Powershell

Hi all!

Today I’m just posting this useful Powershell script to remove a web part from all the pages in a specific site.

It goes through all the libraries you define and looks for instances of the web part and removes to ones it finds.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.WebPartPages")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")

$wpName = "Your_Web_Part_Name";
$checkedOut = @()
$site = new-object Microsoft.SharePoint.SPSite -argumentList "http://yourwebapplicationurl.com";

$webApplication = $site.WebApplication;

foreach($spsite in $webApplication.Sites)
{
	$spweb = $spsite.OpenWeb("your web site name")
	$url = $spweb.Url;

	write-output "Processing $url"

	# libraries to check for the web part on pages
	$libraries = @("Pages");

	foreach($lib in $libraries)
	{
		$list=$spweb.Lists[$lib]
		$title = $list.Title
		foreach($item in $list.Items)
		{
			$WebPageUrl = $item.Url
			write-output "Processing page $WebPageUrl"

			$spWpManager = $spweb.GetLimitedWebPartManager($WebPageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);
			$webparts = @()

			if ($item.File.CheckOutType -ne "None")
			{
				$checkedOut = $checkedOut + $WebPageUrl + ","
			}

			foreach($spwebpart in $spWpManager.Webparts)
			{
				if($spwebpart.Title -eq $wpName)
				{
					$webparts = $webparts + $spwebpart.ID
				}
			}

			foreach($webpartId in $webparts)
			{
				$spWpManager.DeleteWebPart($spWpManager.Webparts[$webpartId])
			}
		}
	}
	write-output "$url has been processed."
	write-output "The following pages were checked out and could not be processed: $checkedOut"

	$spweb.Update();
	$spweb.Dispose();

	if($spWpManager -ne $null)
	{
		$spWpManager.Dispose();
	}
	$spsite.Dispose();
}

The code file can be found here.

See you,

Amadeu.

The Business Analysis Masterclass

The Business Analysis Masterclass is a series of posts by Chris Wright explaining how you can be a better BA working with SharePoint.

The posts are very interesting and cover several simple to apply processes which could be used in lots of projects (involving SharePoint or not). His target is to post 100 articles in a 100 days.

By the way, The Microsoft SharePoint Blog (not the official SharePoint one) is a very good blog with articles divided in categories such as IT Professional, Developer, Project Management and Analysis.

See you,

Amadeu.

Developing for SharePoint Using Visual Studio 2012 – Tech Ed North America

I just watched the video Developing and Managing SharePoint Solutions with Microsoft Visual Studio from Tech Ed North America 2012.

Jay Schmelzer covered the following topics (I also put my opinions about each topic):

  • Web Development versus Sharepoint Development: He stated that on VS2012 what you can do for web development can also be done for SharePoint development. That is really a great achievement for the SharePoint developers.
  • Simplified SharePoint project types: I was really very confusing on VS2010. Why would you create a project for an event handler instead of having a SharePoint and add the event handler to it??
  • Creating SharePoint lists using Visual Studio 2012: That is a cool feature demonstrated by Jay on this video. VS2012 can create the list and support most of the list configurations available. And best of all, no XML involved.
  • Creating Visual Web Parts for Sandboxed Solutions: Now it is part of Visual Studio 2012. If you use Visual Studio 2010, you should use the Visual Studio SharePoint Power Tools.
  • Better integration with the SharePoint Content Database: I didn’t see it much, even though he mentioned it a bunch of times. The only time it really showed knowledge of the content database was when he deployed the list for the second time and VS2012 told him there was a conflict. I was expecting something smarter in the way intellisense works to help you figure out list names, field names, available content types, etc.
  • Using the JavaScript Client Object Model and JQuery: No news here. I was expecting something more from VS2012 on this matter but no
  • Page inspector on IE – Developer Tools (F12): No news here. He just showed what already exists. No VS2012 related feature and by the way, Chrome Developer Tools is much better!
  • Retract is automatic after stopping the debug: That is new and it is also configurable.
  • Deployment config, pre and post deployment steps: All this stuff already exists on VS2010.
  • Less features created on projects: Finally!
  • Manifest file: You can edit it and also have schema completion.
  • Feature dependency: Already existed on VS2010.
  • Deploy to Office 365: Cool feature.

 

He also talked about 2 interesting topics by the end of the session:

Unit test for SharePoint– fake classes: they are going to provide those classes to allow developers to right unit test for SharePoint solutions in a less painful way than what is out there now.

LightSwitch: rapid business application development tool now integrated with SharePoint lists.

 

My rating for the session would be 3 out of 5 because no great/new topics were covered in depth on this session and I was expecting more from VS2012.

 

You can watch other videos from Tech Ed North America 2012 at Channel 9:

http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012

 

 

See you,

Amadeu.