Feeds:
Posts
Comments

Posts Tagged ‘SharePoint’

To have http redirects in a sharepoint we can use something like this in the web.config file

<location path=”oldpage1.htm”>
<system.webServer>
<httpRedirect enabled=”true” destination=”newpage1.html” exactDestination=”true” httpResponseStatus=”Permanent” />
</system.webServer>
</location>

One simple way of doing it using PowerShell is to use the SPWebConfigModication object.

The following script can achieve that

 

$Owner = “redirectMod”
$webApp = Get-SPWebApplication $Url

 

$modification = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$modification.Path = “configuration”;
$modification.Name = “redirect-1” ;
$modification.Sequence = 0;
$modification.Owner =$Owner;
$modification.Type = 0 # EnsureChildNode;
$modification.Value = “<location path='”+$from+”‘><system.webServer><httpRedirect enabled=’true’ destination='”+$to+”‘ exactDestination=’true’ httpResponseStatus=’Permanent’ /></system.webServer></location>”;
$webApp.WebConfigModifications.Add($modification);

$webApp.Update()
$webApp.Parent.ApplyWebConfigModifications()
do{
Start-Sleep -Seconds 2;
Write-Host “.” -NoNewline
$configJobRunning = IsWebConfigModificationJobPendingOrRunning $webApp;
}while ($configJobRunning);

 

Read Full Post »

If we need to add some URL rewrite to a SharePoint site, we can do that using some web.config settings like :

<rewrite>
<rewriteMaps>
<rewriteMap name=”Redirects”>
<add key=”/Page1.html” value=”/Page1″ />
<add key=”/Page2.html” value=”/Page2″ />
</rewriteMap>
</rewriteMaps>
</rewrite>

One way to do that Is to use SharePoint Powershell commands.

The following script achieves that:
[Microsoft.SharePoint.Administration.SPWebConfigModification] $modification = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$modification.Path = “configuration/system.webServer”;
$modification.Name = “rewrite”;
$modification.Sequence = 0;
$modification.Owner =$Owner;
$modification.Type = 0 # EnsureChildNode;
$modification.Value = “”;
$webApp.WebConfigModifications.Add($modification);

$modification = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$modification.Path = “configuration/system.webServer/rewrite”;
$modification.Name = “rewriteMaps”;
$modification.Sequence = 0;
$modification.Owner =$Owner;
$modification.Type = 0 # EnsureChildNode;
$modification.Value = “”;
$webApp.WebConfigModifications.Add($modification);

$modification = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$modification.Path = “configuration/system.webServer/rewrite/rewriteMaps”;
$modification.Name = “rewriteMap”;
$modification.Sequence = 0;
$modification.Owner =$Owner;
$modification.Type = 0 # EnsureChildNode;
$modification.Value = “”;
$webApp.WebConfigModifications.Add($modification);

$modification = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$modification.Path = “configuration/system.webServer/rewrite/rewriteMaps/rewriteMap”;
$modification.Name = “redirect-1”;
$modification.Sequence = 0;
$modification.Owner =$Owner;
$modification.Type = 0 # EnsureChildNode;
$modification.Value = “”;
$webApp.WebConfigModifications.Add($modification);

$modification = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$modification.Path = “configuration/system.webServer/rewrite/rewriteMaps/rewriteMap”;
$modification.Name = “redirect-2”;
$modification.Sequence = 0;
$modification.Owner =$Owner;
$modification.Type = 0 # EnsureChildNode;
$modification.Value = “”;
$webApp.WebConfigModifications.Add($modification);

$webApp.Update()
$webApp.Parent.ApplyWebConfigModifications()

do{
Start-Sleep -Seconds 2;
Write-Host “.” -NoNewline
$configJobRunning = IsWebConfigModificationJobPendingOrRunning $webApp;
}while ($configJobRunning);

References:

https://blog.kenaro.com/2010/09/02/add-web-config-modification-with-powershell-spwebconfigmodification/ 

 https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module 

Read Full Post »

When running Enable-SPFeature, you may get the weird error:

“Enable-SPFeature : The file is currently checked out or locked for editing by another user.”

 

One possible cause of this issue could be that some file(s) the are deployed by the feature could be checked out by a user.

Checking the ULS logs you could find something like

 

Instantiating module “NAMEOFMODULE”: File could not be added at URL “FILENAME.jpg: Error 689225296 99e77593-d0d4-49df-adcc-c8f8251fbb82
04/06/2017 20:53:42.02 PowerShell.exe (0x107C) 0x1334 SharePoint Foundation Monitoring b4ly High Leaving Monitored Scope (SPSqlClient). Execution Time=11589.5652 99e77593-d0d4-49df-adcc-c8f8251fbb82
04/06/2017 20:53:42.02 PowerShell.exe (0x107C) 0x1334 SharePoint Foundation General 8kh7 High The file is currently checked out or locked for editing by another user.<nativehr>0x80070021</nativehr><nativestack></nativestack> 99e77593-d0d4-49df-adcc-c8f8251fbb82
04/06/2017 20:53:42.03 PowerShell.exe (0x107C) 0x1334 SharePoint Foundation General aix9j High SPRequest.EnableModuleFromXml: UserPrincipalName=i:0).w|s-1-5-21-995927836-1113283497-4239367599-17896, AppPrincipalName= ,bstrSetupDirectory=C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\Template ,bstrFeatureDirectory=Features\ABCDEP ,bstrUrl=,bstrXML=<Module Name=”images” Path=”Style Library\images” Url=”Style Library/images” RootWebOnly=”TRUE” xmlns=”http://schemas.microsoft.com/sharepoint/”><File ReplaceContent=”True” Type=”GhostableInLibrary” Path=”favicon.ico” Url=”favicon.ico” /><File ReplaceContent=”True” Type=”GhostableInLibrary” Path= ,fForceUnghost=False ,pModuleContext=<null> 99e77593-d0d4-49df-adcc-c8f8251fbb82
04/06/2017 20:53:42.03 PowerShell.exe (0x107C) 0x1334 SharePoint Foundation General ai1wu Medium System.Runtime.InteropServices.COMException: The file is currently checked out or locked for editing by another user.<nativehr>0x80070021</nativehr>

Read Full Post »

Problem:

The list/library template you just created by saving List or library as a template is not showing up when you try to create a new list/library based on that template.

 

One thing to check first is to go to the List templates Gallery (Site settings-> List templates under web designer galleries).

If the template in question does NOT have product Version and Feature ID assigned. Then the problem might be that the ParserEnabled property is set to false on that site.

 

Resolution:

Using PowerShell , set the ParserEnabled property to true.

$web = Get-SPWeb <url of web>
$web.ParserEnabled = $true
$web.Update()

 

Reference: https://support.microsoft.com/en-us/kb/2779729

 

Thanks to

https://social.technet.microsoft.com/Forums/sharepoint/en-US/112ac0b0-c6f0-40a7-8a03-19737c29d1e4/sharepoint-stp-template-is-missing-language-version-and-feature-id?forum=sharepointgeneralprevious

Read Full Post »

Here is a simple script to create the site structure for SharePoint Online based on a csv file.

The script is using the Client-side SharePoint PowerShell project from Codeplex (https://sharepointpowershell.codeplex.com/ ).

 

In order to create the site structure just fill the csv file of the following format

Url,Name,Template,Description,Language
Blog,Blog,BLOG#0,Blog,1033
Subsite1, SubSite1, STS#0, Name1, 1033
SubSite1/Subsite11, Name11, STS#0, Description, 1033
SubSite1/Subsite11/Subsite1111, Name3, STS#0, Description, 1033

 

And then use the following script

 

Import-Module "$PSScriptRoot\spps.psm1"
Import-Module "$PSScriptRoot\spps.subsites.psm1"
Import-Module "$PSScriptRoot\ConfigCredentials.ps1"

Initialize-SPPS -siteURL $O365SiteUrl -isOnline $true -onlineusername $username -onlinepassword $password

Import-Csv $PSScriptRoot\SiteStructure.csv  | ForEach-Object{

    $name = $_.Name
    $template = $_.Template
    $description = $_.Description
    $lang = $_.Language
   
    Write-Host "Processing " $name " "  $_.Url
    Open-Rootsite
   
    $relUrl = ""   
    foreach($subsite in $_.Url -split "/")
    {
        $relUrl += "/"+ $subsite
        try
        {
            Open-Subsite -relativeUrl $relUrl
            Write-Host "Site" [$relUrl] "Already exists"
        }
        catch
        {
            Write-Host "Trying to create" $subsite
            Add-Subsite -title $name -url $subsite -webTemplate $template -language $lang -description $description
        }
    }
    Write-Host " ———————– "
}

 

Note, the Script ConfigCredentials.ps1 is used to store the Site Url and the credentials as follows

$O365SiteUrl = “https://url_here
$username = username@domain.com
$password = "password"

 

Note: to make sure the script behaves as expected, make sure that the hierarchy in the csv file is in order. i.e.

Subsite1
Subsite1/Subsite2

in other words do no list the sub site before its parent site.

Read Full Post »

For some reason if you set the Properties Hashtable of the File added as (“Title”, “TitleValue”), sharePoint just ignores it.

 

The Trick is to set the Title using (“vti_title”, “TitleValue”)

Read Full Post »

I had a custom web part that is running code that required elevated privileges and was running within SPSecurity.runWithElevatedPrivileges  as below

 

SPSecurity.RunWithElevatedPrivileges(delegate()

{

   SPSite siteColl = SPContext.Current.Site;

   ….

}

I kept throwing an access denied error.

after some investigation I found the solution at this useful blog.

http://blogs.msdn.com/b/sasohail/archive/2010/10/31/access-denied-within-spsecurity-runwithelevatedprivileges.aspx

 

the problem in short is, I was using a reference to the SPSite obtained from the SPContext. This reference to SPSite was created before the code entered the RunWithElevatedPrivileges block. Therefore, the reference to the SPSite was running under the current user privileges even though it was placed within the RunWithElevatedPrivileges block.

 

The solution is to obtain a new reference to the SPSite created within the RunWithElevatedPrivileges block as shown below.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite siteColl = new SPSite(SPContext.Current.Site.ID))
    ….

}

Read Full Post »

Older Posts »