Monday, July 7, 2014

update aspx or any file through Powershell

I had this problem of SharePoint people picker issue, where in the People picker restricted to particular SharePoint group was having UI problem .Problem was that when you try to search users a popup open with the users in that SharePoint group for you to be selected .

Problem is that the Height of the people picker popup in IE10 was very small as below.
It was working fine in IE9,IE11 and IE10 quirks mode


The files in use are picker.aspx and pickerdialog.aspx .

There were two solutions

Solution-1 : Edit the picker.aspx



·         Locate the div with ID = ‘resultcontent ‘and add style property to it. Set the min-height value from inside the style property like below.

<div id='resultcontent' style="min-height:300px" class="ms-pickerresultdiv">
 
 
Solution-2 : Edit the Pickerdialog.master 
·         In the Meta tags section, set the “X-UA-Compatible” to “IE=EmulateIE9” to make it look like below.
 
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
Here in this option the page is rendered in IE9 mode  

Client chose the solution-2 and they wanted to automate this using the PowerShell ,hence I wrote the below PowerShell command to take backup of the current pickerdialog.aspx and update the tag in the file which is present in 15 hive, this ps1 has to run in all web front-end server
Below is the PowerShell command
 
 
 
 
Write-host -ForegroundColor Green "Updating Pickerdialog.master file started .........!!"
Write-host -ForegroundColor Green "Creating backup of current file ........."
$a =(Get-Date).ToString('MM-dd-yyyy hh-mm-ss')
$filename = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog-{0}.master" -f $a
copy "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog.master" $filename
Write-host -ForegroundColor Green "Backup of current file completed ........."
(Get-Content "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog.master") |
Foreach-Object {$_ -replace "<meta http-equiv=`"X-UA-Compatible`" content=`"IE=10`"/>", "<meta http-equiv=`"X-UA-Compatible`" content=`"IE=EmulateIE9`"/>"} |
Set-Content "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\pickerdialog.master"
Write-host -ForegroundColor Green "Updating Pickerdialog.master file completed ........."
pause
 
 
 
 

Thursday, May 15, 2014

Modal Popup- close sharepoint page and sharepoint popup page in code behind

Below is the code to close a SharePoint popup window on button click or any event from code behind

// Close if dialog

HttpContext context = HttpContext.Current;

if (HttpContext.Current.Request.QueryString["IsDlg"] != null)



{
 
context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup()</script>");




}
 
else

SPUtility.Redirect(SPContext.Current.Web.Url, SPRedirectFlags.UseSource, HttpContext.Current);




Source attribute is a Query string which holds the url of the source page from where the page is usually called .This is default behavior of SharePoint. We can use this to navigate when the popup is closed and redirect to same source page as shown above

Eg: http://webpalication:1111?Source=http:wwww.google.com


 

Friday, May 9, 2014

Add Sharepoint Navigation links with audience targeting through powershell

Below is the powershell command to add Navigation links in SharePoint.This was tested in SharePoint 2013 environment.This script will check if the link is present in the site if not it will add the links along with audience targeting



$snapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }

if ($snapin -eq $null) {

Write-Host "[INIT] Loading SharePoint Powershell Snapin"

Add-PSSnapin "Microsoft.SharePoint.Powershell"


}

 
 
$Web = Get-SPWeb http://testWebapplication:7777

$TopNav = $Web.Navigation.TopNavigationBar

Write-Host -ForegroundColor Green "Creating Navigation links ......................."



$Heading = $TopNav | where { $_.Title -eq "Link1" }

if($Heading -eq $null)



{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Link1", "/Lists/CreateNewPublication/DocProjects.aspx");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()





}

 
 
$Heading = $TopNav | where { $_.Title -eq "Search" }

if($Heading -eq $null)


{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Search", "/SitePages/Search.aspx");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()


}
 
$Heading = $TopNav | where { $_.Title -eq "Google" }

if($Heading -eq $null)


{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Google", http://www.google.com);

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()


}
 
$Heading = $TopNav | where { $_.Title -eq "Yahoo" }

if($Heading -eq $null)



{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Yahoo", http://yahoo.co.in);

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Heading.Properties["Audience"] = ";;;;" + "IK,IL,R,C"

$Heading.update()

$Web.Update()





}
 
$Heading = $TopNav | where { $_.Title -eq "Reports" }

if($Heading -eq $null)



{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @("Reports", "/SitePages/Reports.aspx");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Heading.Properties["Audience"] = ";;;;" + "PM,TL,IL,C"

$Heading.update()

$Web.Update() 



}
 
  $Heading = $TopNav | where { $_.Title -eq " Help" }

if($Heading -eq $null)

{
 
$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList @(" Help", "/Lists/HelpLibrary ");

$Heading = $Web.Navigation.TopNavigationBar.AddAsLast($newLink)

$Web.Update()


}
 
Write-Host -ForegroundColor Green "Navigation link creation completed"

Pause