Pages

Search This Blog

Saturday, March 23, 2013

Create Managed Path via PowerShell



#-----Function to Load SharePoint PowerShell Environment----#
function LoadSharePointPowerShellEnvironment
{
 write-host "Setting up PowerShell environment for SharePoint..." -foregroundcolor Yellow
 Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
 write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
}



function Create-SPManagedPath
{
  param ($webApplicationUrl, $managedPathName)
  $managedPath = Get-SPManagedPath -WebApplication $webApplicationUrl -Identity $managedPathName -ErrorAction SilentlyContinue
  if ($managedPath -ne $null)
  {
  Write-Host "Managed path $managedPathName already exists."
  return
  }

  Write-Host "Creating managed path $managedPathName ..."
New-SPManagedPath –RelativeURL $managedPathName -WebApplication $webApplicationUrl
  Write-Host "Managed path $managedPathName created sucessfully" -foregroundcolor Green
}


LoadSharePointPowerShellEnvironment
Create-SPManagedPath "http://mywebappurl" "logical"

Tuesday, March 19, 2013

Convert SharePoint 2010 solution to SharePoint 2013 in Visual Studio


Recently I tried to convert a SharePoint solution in visual studio 2010 to Visual Studio 2012, but it gave me errors like:

"The primary reference "Microsoft.SharePoint" could not be resolved because it has an indirect dependency on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework."

You can refer to below steps if you want to convert your SharePoint 2010 solution (created with visual studio 2008 or 2010) to visual studio 2012 for SharePoint 2013: 
  • Open your visual studio .csproj file in notepad or visual studio and change the value of  tag "TargetFrameworkVersion" to 4.5

  • Add a new tag just below the one you modified in above step as:
        <TargetOfficeVersion>15.0</TargetOfficeVersion>

This way your modified csproj file will have attributes as shown below:


  • You will also need to change the SharePoint Product version property of your  Package file from 14.0 to 15.0 as shown below. 
  •  In your aspx pages and code files, where you are referencing any image from Layouts folder, you need to append "/15" as:
           /_Layouts/15/<your image path>