Tuesday, April 30, 2013

The item may be too large or corrupt. You may also verify that you have the latest version of this IFilter.

Problem:
SharePoint search didn't return search results on Large lists and libraries. On analyzing search crawl log, found the error logged: "The item may be too large or corrupt. You may also verify that you have the latest version of this IFilter.".
The item may be too large or corrupt. You may also verify that you have the latest version of this IFilter.
Solution: 
Make these registry changes in Index server and restart SharePoint search service. Once done, trigger the crawl again.
Key
Default Value
New Value
HKLM\SOFTWARE\Microsoft\Office Server\12\Search\Global\GatheringManager\DedicatedFilterProcessMemoryQuota
104,857,600
209,715,200
HKLM\SOFTWARE\Microsoft\Office Server\12\Search\Global\GatheringManager\FilterProcessMemoryQuota
104,857,600
209,715,200
HKLM\SOFTWARE\Microsoft\Office Server\12\Search\Global\GatheringManager\FolderHighPriority
50
500

Thanks to Technet forums!
http://social.technet.microsoft.com/Forums/en-US/sharepointsearchlegacy/thread/138e2e68-9bf7-4a1c-9519-ace6a78ddaa5

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Replace Content Editor Web Part (CEWP) Links with PowerShell

After a SharePoint Migration with URL change, had to find and replace the links from SharePoint content Editor Web Part for all SharePoint sites in a web Application. Here is the PowerShell Script to find and replace links from Content Editor Web Part.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$OldLink="http://sp10.crescent.com"
$NewLink="http://sharepoint2010.crescent.com"

#Get all Webs
$webs = Get-SPWebApplication "http://sharepoint.crescent.com" | Get-SPSite -Limit All | Get-SPWeb -Limit All
 
#Iterate through webs
foreach ($web in $webs)
{
#Get All Pages from site's Root into $AllPages Array
$AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})
 
#Search All Folders for Pages
foreach ($folder in $web.Folders)
    {
        if($folder.Name -ne "Forms") #Leave "Forms" Folder
        {
            #Add the pages to $AllPages Array
            $AllPages += @($folder.Files | Where-Object {$_.Name -match ".aspx"})
        }
    }
  
 #Iterate through all pages
 foreach($Page in $AllPages)
  {
     #Web Part Manager to get all web parts from the file
     $WebPartManager = $web.GetLimitedWebPartManager( $Page.ServerRelativeUrl,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
 
     #Iterate through each web part
     foreach($webPart in $WebPartManager.WebParts) 
      {
        # Get All Content Editor web parts with specific Old Link
        if( ($webPart.Content.InnerText -like '*'+$OldLink+'*' ) -and ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart]) )
        {
     #Get the Old content from CEWPs
     $OldContent =  $webPart.Content
           $OldContentXml = $OldContent.InnerText

           #Replace the Old Links
     $XmlDoc = New-Object System.Xml.XmlDocument
     $NewContentXml= $XmlDoc.CreateElement("content") 
           $NewContentXml.InnerText= $OldContentXml.Replace($OldLink, $NewLink)
     
           #Set content and Save
           $webpart.Content = $NewContentXml     

           $webPartManager.SaveChanges($webPart);
           Write-Host "Replaced a link in $($Page.ServerRelativeUrl))"
         }
      }
   }
}

Update Content Editor content in Publishing Sites:
We'll have to call Check-Out, Check-in methods on publishing sites. Here is the Script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL ="https://portal.crescent.com"
$OldLink="http://sp10.crescent.com"
$NewLink="http://sharepoint2010.crescent.com"

#Get the web
$Web = Get-SPWeb $WebURL 
#Get Publishing Web
$PublishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
#Get Pages Library
$PublishingPages = $PublishingWeb.GetPublishingPages()
 
#Iterate throgh each page
foreach ($Page in $PublishingPages)
{   
#Checkout the page
$Page.CheckOut() 

#Web Part Manager to get all web parts from the file
$WebPartManager = $web.GetLimitedWebPartManager($Page.Url,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
  
 #Iterate through each web part
 foreach($webPart in $WebPartManager.WebParts) 
  {
    #Get All Content Editor web parts with specific Old Link
    if( ($webPart.Content.InnerText -like '*'+$OldLink+'*' ) -and ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart]) )
    {
       #Get the Old content from CEWPs
       $OldContent =  $webPart.Content
       $OldContentXml = $OldContent.InnerText
 
       #Replace the Old Links
       $XmlDoc = New-Object System.Xml.XmlDocument
       $NewContentXml= $XmlDoc.CreateElement("content") 
       $NewContentXml.InnerText= $OldContentXml.Replace($OldLink, $NewLink)
  
       #Set content and Save
       $webpart.Content = $NewContentXml    
 
       $webPartManager.SaveChanges($webPart);
       Write-Host "Replaced a link in $($Page.ServerRelativeUrl))"
     }
  }
#Check in and Publish the page  
$page.CheckIn("CEWP Updated")  
$Page.ListItem.File.Publish("CEWP Updated")}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Hide List Form Field in SharePoint 2013 using jQuery

My earlier post listed various methods such as C# Object model, PowerShell, JavaScript methods to hide columns in SharePoint list forms: Hide Columns in SharePoint List NewForm, EditForm and DispForms

Now, lets hide fields in SharePoint list form pages using jQuery. Lets say you have a field called "Parent Project" and want to hide it from All SharePoint list forms such as NewForm.aspx, EditForm.aspx and DispForm.aspx.

jQuery script to hide SharePoint field in New, Edit and Display Forms:
<script src="http://code.jquery.com/jquery-1.2.6.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() 
{
$('td.ms-formlabel:contains("Parent Project")').parent().hide();
});
</script>

These scripts can be placed in Script Editor web part, Custom JS file linked in Master page or as part of SharePoint delegate controls.

To hide fields in SharePoint list form pages using jQuery, Navigate to Newform.aspx or any other form page, Click on site settings icon >> Edit page >> Insert a Script editor web part and paste the above codes accordingly.
hide sharepoint list column using jquery
Consider downloading and placing jQuery js file to your SharePoint hive in case, for faster retrieval.
E.g. Instead of "http://code.jquery.com/jquery-1.2.6.min.js", you'll placing it in _layouts folder and referring as: http://teamsites.crescent.com/_layouts/jquery-1.2.6.min.js

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint 2010 Central Administration Links Missing, Ribbon Buttons Disabled - Fix

After setting up a new SharePoint 2010 farm, I noticed most of the SharePoint 2010 Ribbon buttons including "New" "Extend" buttons are disabled!
SharePoint 2010 Central Administration Ribbon Buttons Disabled

Also few links in SharePoint 2010 Central Administration were missing: E.g.
  • "Manage Services on the Server" link missing under Servers
  • "Configure Incoming E-Mail Settings" under E-mail and Text Messages (SMS).
  • "Perform a Backup" "Restore from a backup" Configure Backup Settings" links are missing in "Farm Backup and Restore"
    SharePoint 2010 Central Administration Links Missing
Root cause: This issue happens when a SharePoint Farm Administrator doesn't has local administrator rights on the SharePoint Server! It also happens when UAC or IE Enhanced Security Configuration (ESC) is enabled!

Fix: Add the user to "Administrators" user group of the all SharePoint Servers. Get Central Administration Ribbon Buttons and Links Disabled!Disable UAC from Control Panel, Disable IE ESC from Server Manager of Windows Server 2008.

In an another case, Fix was: Synced all SharePoint Servers Timezone with AD Domain controller by running "w32tm /resync"

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Add User To SharePoint Group Programmatically with STSADM, C# and PowerShell

Apart from SharePoint User Interface, We can programmatically add users to SharePoint group or site in these ways:
  • Using STSADM command line tool to add users 
  • Add users to Sharepoint site/group using C# Object Model
  • Add users to SharePoint Group using PowerShell

1. Using STSADM command line tool to add users:
To add user to the SharePoint site, we can use stsadm classic command line tool.  bulk users to add from a CSV file:
  • Add user to a SharePoint group:
    stsadm -o adduser -url "http://sharepoint.crescent.com/sites/marketing" -userlogin crescent\UserName -useremail UserName@crescent.com -group "Marketing Members" -username "User Name"
  • To Add a User directly user under "Site Permissions"
    stsadm -o adduser -url "http://sharepoint.crescent.com/sites/marketing" -userlogin crescent\UserName -useremail UserName@crescent.com -role "Full Control" -username "User Name"
  • To Add a user as Site collection Administrator:
    stsadm -o adduser -url "http://sharepoint.crescent.com/sites/marketing" -userlogin crescent\UserName -useremail UserName@crescent.com -group "Marketing Owners" -username "User Name" -siteadmin
Stsadm -o Adduser operation Technet reference: http://technet.microsoft.com/en-us/library/cc262627.aspx

 

2. Add Users to SharePoint Programmatically using C# :

Adding users to SharePoint site programmatically: Here is how we can add users to SharePoint site With .Net Object Model C# Code. (This works both in SharePoint 2007 and SharePoint 2010)
   
    using(SPSite site=new SPSite("http://sharepoint.crescent.com"))
       {
            using (SPWeb web = site.RootWeb)
                   {
                 string GroupName="SharePoint Members";
                 SPGroup group = web.Groups[GroupName];
                       
                        //To Get the Default Members group
                        //SPGroup group = web.SiteGroups.Web.AssociatedMemberGroup;
 
                 SPUser user = web.EnsureUser("Crescent\\Salaudeen");
                 group.AddUser(user);
                 web.Update();
                    }
 }


3. Add User to SharePoint 2010 using PowerShell Cmd-lets:
New-SPUser:
New-SPUser -UserAlias "domain\user" -Web "http://sharepoint.crescent.com/sites/marketing" -Group "Marketing Owners"
This will create a add a new User to SharePoint site to the particular group. If you execute this command for the next time, (without deleting the user from site collection) this command has no effect!

Set-SPUser:
Set-SPUser -Identity "domain\user" -Web "http://sharepoint.crescent.com/sites/marketing" -Group "Marketing Owners"
This will add existing SharePoint users account to the provided group, but will give error when you try add a new user to SharePoint site. (which is obvious! We can't set the user property, if the user doesn't exists in SharePoint site, isn't it?)

Add User to SharePoint Group using PowerShell

#Get the Web
$web=Get-SPWeb "http://sharepoint.crescent.com/sites/marketing"
#Get the Group
$Group= $web.Groups["Marketing Owners"]
$userName = "domain\userName"

#Add User to the site collection
$user = $web.EnsureUser($UserName)

#Add User to the Group
$group.AddUser($user)


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, April 29, 2013

Import From CSV File into SharePoint List using Powershell

Periodically, We needed the data from a CSV file, which is generated by an external Third-party application, to be imported to SharePoint 2010 List. To fulfill this requirement,  I wrote a quick PowerShell script which will read the CSV file and import the data into SharePoint list using PowerShell.
Import CSV to SharePoint List using PowerShell

PowerShell Script to import from CSV file to SharePoint 2010 list
Lets import csv file to SharePoint list using PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Read the CSV file - Map the Columns to Named Header (CSV File doesn't has Column Header)
$CSVData = Import-CSV -path "C:\Data.csv" -Header("Title", "Description", "Priority", "AssignedTo", "DueDate", "Status")

#Get the Web
$web = Get-SPWeb -identity "http://sharepoint.crescent.com/sites/Marketing/"

#Get the Target List
$list = $web.Lists["Log"]

#Iterate through each Row in the CSV
foreach ($row in $CSVData) 
 {
   $item = $list.Items.Add();
   
   $item["Title"] = $row.Title
   $item["Description"] = $row.Description
   $item["Priority"] = $row.Priority

   #Set the People Picker Field value
   $item["Assigned To"] = Get-SPUser -Identity $row.AssignedTo -web "http://sharepoint.crescent.com/sites/Marketing/"
    
   #Set the Date Field value
   $item["Due Date"] = Get-Date $row.DueDate

   $item["Status"] = $row.Status
   $item.Update()
 }

We scheduled this script through Windows Task Scheduler: How to schedule a powershell script using windows task scheduler

In an another case, before importing a list item from CSV file, I had to check whether the item which is being added, is already exists in the List. If It doesn't exists, let the script add new item from CSV file.
$ListItems = $reconciliationList.Items | Where-Object { $_.Item("Title") -eq $row.Title}

  if ($ListItems -eq $null)
    { 
      #ADD Item to the List
    }

Update Lookup values in PowerShell:
Unlike other fields, SharePoint look-up fields can't be set directly. We have to get the lookup parent id, to update the lookup field values.
   
 #For Lookup values: Lookup Parent List
 $DepartmentList=$web.Lists["Department"]

 #Get the Lookup Item from Parent List
 $LookupItem = $departmentList.Items | Where-Object { $_.Item("Title") -eq $row.Department}

 if($LookupItem -ne $null)
 {
     $deptLookup = New-Object Microsoft.Sharepoint.SPFieldLookupValue($LookupItem.ID,$row.Department)
 }

 #Set the Lookup field value
 $item["Department"] = $deptLookup
   
 $item.Update() 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, April 28, 2013

Export SharePoint List Items to CSV using PowerShell

Requirement: Export SharePoint List items to a CSV file.

Export SharePoint list data to CSV using PowerShell:
This script exports SharePoint list to csv using PowerShell. It retrieves all list items, Filters it based on the provided column value and then creates a property to hold the list item values and then appends the objects which holds the list item values to an array.

Finally, using the Export-CSV Cmdlet, we are exporting the data to CSV file.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web
$web = Get-SPWeb -identity "http://sharepoint.crescent.com/sites/Operations/"

#Get the Target List
$list = $web.Lists["Monthly Schedule Log"]

#Array to Hold Result - PSObjects
$ListItemCollection = @()

 #Get All List items where Status is "In Progress"
 $list.Items |  Where-Object { $_["Status"] -eq "In Progress"} | foreach {
 $ExportItem = New-Object PSObject 
 $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
 $ExportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $_["Department"]
 $ExportItem | Add-Member -MemberType NoteProperty -name "Status" -value $_["Status"]
 $ExportItem | Add-Member -MemberType NoteProperty -name "Priority" -value $_["Priority"]

 #Add the object with property to an Array
 $ListItemCollection += $ExportItem
 }
 #Export the result Array to CSV file
 $ListItemCollection | Export-CSV "c:\ListData.txt" -NoTypeInformation                        

#Dispose the web Object
$web.Dispose()

Export All fields in the list to Excel using PowerShell
In an another case, required to export all fields from the list to CSV
Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
 
#Variables
$SiteUrl="http://opera.crescent.com"
$OutPutFile = "C:\UserInfoList.csv"
 
#Get Web and User Information List
$web = Get-SPWeb $SiteUrl
$UserInfoList = $Web.SiteUserInfoList
Write-host "Total Number of Items Found:"$UserInfoList.Itemcount

#Array to Hold Result - PSObjects
$ListItemCollection = @()
  
 #Get All List items where Status is "In Progress"
 $UserInfoList.Items | foreach {
 write-host "Processing Item ID:"$_["ID"]
 
   $ExportItem = New-Object PSObject 
   #Get Each field
   foreach($Field in $_.Fields)
    {
        $ExportItem | Add-Member -MemberType NoteProperty -name $Field.InternalName -value $_[$Field.InternalName]  
    }
    #Add the object with property to an Array
    $ListItemCollection += $ExportItem

}    
#Export the result Array to CSV file
$ListItemCollection | Export-CSV $OutPutFile -NoTypeInformation 
Write-host "User Information List Exported to $($OutputFile) for site $($SiteURL)"
 
$web.Dispose()


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


"The Content Type is in Use" Error in SharePoint - Find Where and Delete

We don't needed a particular content type anymore and wanted to delete the content type.

Navigated to:
  •     Site Actions >> Site Settings.
  •     Under Galleries click Site content types.
  •     Select the Content type to delete by clicking on its name.
  •     Click "Delete this site content type" link.
Oops!  SharePoint returns an error: Error: "The Content Type is in Use".  
the content type is in use sharepoint
Looks like its a common issue when trying to delete content types. I've seen this "The content type is in use" error in SharePoint 2007 and in SharePoint 2010. The error message clearly indicates that the content type is still in use and cannot be deleted. Yes, We had assigned the content type to some list and libraries. But I dunno where!

How to delete a content type and get rid of "The content type is in use" error in SharePoint? Well, to solve this issue: We've to Find the locations where the particular content type is being used and delete the the associations and items.

Find the locations where our Content type is in use:

Lets use "SharePoint Manager 2010" to find where our content type is being used.
  • Download the SharePoint Manager 2010 from Codeplex
  • Open SPM and Navigate to the target Site Collection where your Content Type is located
  • Go to Content Type >> Usages to find all content type usages
  • Delete all the usages of the Content Typecannot delete content type the content type is in use
Once done, You can delete your content type with out any issues. We can use PowerShell also.

 

PowerShell Script to find where a specific Content Type is being used:

We can use PowerShell also to find where a specific Content Type is being used:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the site
$site = Get-SPSite "http://sharepoint.crescent.com/sites/marketing"
#Name of the Content Type
$ContentTypeName = "Travel Request"
  
#Loop through all web
 Foreach ($web in $site.AllWebs)
    {
  #Get the Content Type
  $ContentType = $web.ContentTypes[$ContentTypeName]
  
  #Check if content type exists
     if($ContentType -ne $null)
  {
   #Get the Content Type Usage
   $CTypeUsages = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ContentType)

   if ($CTypeUsages.Count -gt 0) 
   {
       foreach ($CTypeUsage in $CTypeUsages) 
    {
            write-host $CTypeUsage.Url
       }
   }
  }
  $web.Dispose();
 }
This will provide list of locations where the specific content type is being utilized. Now, We've to Delete those items or change their content types and remove the content type associations from lists and libraries.

Change Content Type Programmatically:

If you want to delete a content type, You have to make sure No Lists/Library and No List Item/Document is using the content type! In other words, You got to either change the content type of existing items created with the particular content type or delete those items using the specific content type!!

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web
$site = Get-SPSite "http://sharepoint.crescent.com/sites/marketing"
#Name of the Content Type
$ContentTypeName = "Travel Request"
$NewCTypeName="Travel Request V2"

#Loop through all web
 Foreach ($web in $site.AllWebs)
    {
  #Get the Content Type
  $ContentType = $web.ContentTypes[$ContentTypeName]
  
  #Check if content type exists
     if($ContentType -ne $null)
  {
   #Get the Content Type Usage
   $CTypeUsages = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ContentType)

   if ($CTypeUsages.Count -gt 0) 
   {
       foreach ($CTypeUsage in $CTypeUsages) 
    {
           #Get the list where specific content type in use write-host 
     $list = $web.GetList($CTypeUsage.Url)
     #Check for Items using the content type
     $SPQuery = "<Where><Eq><FieldRef Name='ContentType'/><Value Type='Text'>$($ContentTypeName)</Value></Eq></Where>"
           $ListItems = $list.GetItems($SPQuery)
     #Change the Content Type of All existing Items which are currently using the specific content type
           for($i=$ListItems.Count-1; $i -ge 0; $i--)
           {
      $ListItem= $ListItems[$i]
      write-host "Changing Content Type of List Item with ID: $($ListItem.ID)"
               $ListItem["ContentTypeId"]= $list.ContentTypes[$NewCTypeName].id
      $ListItem.Update()
           }
  
     #Delete the content type from list
     $list.ContentTypes.Delete($list.ContentTypes[$ContentTypeName].id)
           write-host "Deleted the Content type from:$($CTypeUsage.Url)" 
     
    }
   }
  #Delete the Content Type now!
  $ContentType.Delete()
  write-host "Content Type $($ContentTypeName) Deleted!"
  }
  $web.Dispose();
 }

 

Deleting a Particular Content Type including all items based on the content type:

Delete All Items which are currently using the specific content type
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web
$site = Get-SPSite "http://sharepoint.crescent.com/sites/marketing"
#Name of the Content Type
$ContentTypeName = "Travel Request"
  
#Loop through all web
 Foreach ($web in $site.AllWebs)
    {
  #Get the Content Type
  $ContentType = $web.ContentTypes[$ContentTypeName]
  
     #Check if content type exists
     if($ContentType -ne $null)
  {
   #Get the Content Type Usage
   $CTypeUsages = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ContentType)

   if ($CTypeUsages.Count -gt 0) 
   {
       foreach ($CTypeUsage in $CTypeUsages) 
    {
           #Get the list where specific content type in use
     $list = $web.GetList($CTypeUsage.Url)
     #Check for Items using the content type
     $SPQuery = "<Where><Eq><FieldRef Name='ContentType'/><Value Type='Text'>$($ContentTypeName)</Value></Eq></Where>"
           $ListItems = $list.GetItems($SPQuery)
           for($i=$ListItems.Count-1; $i -ge 0; $i--)
           {
                   write-host "Deleted List Item with ID: $($ListItems[$i].ID)"
                   $DeletedItem= $ListItems[$i].recycle()
           }
  
     #Delete the content type from list
     $list.ContentTypes.Delete($list.ContentTypes[$ContentTypeName].id)
                   write-host "Deleted the Content type from:$($CTypeUsage.Url)" 
     
    }
   }
  #Delete the Content Type now!
  $ContentType.Delete()
  write-host "Content Type $($ContentTypeName) Deleted!"
  }
  $web.Dispose();
 }

BTW, I read somewhere, To fix "the content type is in use" error in SharePoint 2010, we must delete the list items of particular content type from both End-user Recycle bin & Admin Recycle bin! But I didn't delete them from recycle bin and still I'm able to delete the content types. I didn't face any issue so far.


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, April 24, 2013

SharePoint Survey - Redirect to Thank You Page on Finish

Requirement is to redirect users to Thank You Page in SharePoint Survey on clicking Finish button.

One quick trick comes to my mind is: Appending Source parameter to the Survey's NewForm URL.
E.g.
http://sharepoint.crescent.com/Lists/TownhallMeetingSurvey/NewForm.aspx?source=/SitePages/thankyou.aspx

Not a bad idea, But the problem is: It doesn't matter whether you click on "Finish" or Cancel button, You will be redirected to "Thank You" page! Also, it won't work when you have Branching enabled in SharePoint Survey!

How to Create a Thank You page for SharePoint 2010 Survey:
Lets overcome the above issue with SharePoint designer.

1. Create a new Web Part page (not Wiki page!) and place some descriptive content and/or images in it. I've made the below page. Named it as "thankyou.aspx" under SitePages.
 sharepoint 2010 survey thank you page

2. Open the site in SharePoint Designer, Go to "Forms" section. Create a New Form by clicking on "New Item Form"
sharepoint 2010 survey thank you

 3. Give it a Name,  Choose form type as "New Item Form" and enable "Set as default form for the selected type" and click on "Ok" to create the new form.
sharepoint survey redirect

4.  Edit the New form we've just created. Open the "New.aspx" page in SharePoint Designer. Go to Design view and delete all two "Finish" buttons.

5.  Insert SharePoint Form Action button from "Insert Menu >> SharePoint >> Form Action Button"
sharepoint 2010 survey finish redirect

6. Select the Form Actions "Commit" and "Navigate to Page" and click "OK"
sharepoint survey thank you page

7. Click on the "Form Action" input button and go to code view. Update the code for input button as:
<input type="button" value="Finish" name="btnFormAction" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/sites/marketing/SitePages/thankyou.aspx}')}" style="width: 119px" /> 

8. Save and close the page. That's all!

See the SharePoint 2010 survey thank you page in action:
sharepoint 2010 survey add thank you page

Another method to add thank you page in SharePoint 2010 survey:
If you don't want to use SharePoint designer method as illustrated above, There is an another way. Create an additional question at the end in the survey, as "Thank You for participating in Survey! Click on Finish to complete." of  "Single Line of Text". Add page separator just before this last question. Go to the Survey, Navigate to the last question and Edit the page. Insert a CEWP, place the below code in it.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> 
//Or place the jquery.js file in 14 hive and refer it
<script type="text/javascript">
 $(document).ready(function()
  {
      //Hide the Text field for Thank you Question
      $("input[title$='Thank You for participating in Survey! Click on Finish to complete.']").parent('span').parent('td').parent('tr').hide();
  
 });
</script>
This code will hide the single line of text input field and give thank you message. See the above code in action:
sharepoint 2010 survey thank you message
Here is my another post on sending users to Thank you page from SharePoint list forms:
Redirect Users to Thank You page from NewForm.aspx in SharePoint

Update: Use this Script in a Script Editor Web part for SharePoint 2013/2016:
<script type="text/javascript" language="javascript">

function changeRedirect(options) {
    for (var i = 0, buttons = document.querySelectorAll(options.selector); i < buttons.length; i++) {
        var newOnClick = function(originalOnClick) {
            return function(){
                Nav.navigate = STSNavigate = function() {
                    window.location = options.redirectTo
                }
                originalOnClick()
            }
        }
        buttons[i].onclick = newOnClick(buttons[i].onclick)
    }
}
 
document.addEventListener("DOMContentLoaded", function(event) {
    changeRedirect({
        selector:   "input[value=Save]",
        redirectTo: "https://yoursite.com/pages/thankyou.com"
    })
    changeRedirect({
        selector:   "input[value=Cancel]",
        redirectTo: "https://yoursite.com/"
    })
})

</script>


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, April 23, 2013

SharePoint 2007 Profile Import Job Stuck

It happens sometimes. SharePoint 2007 profile import job get stuck at enumerating or importing stage and forever without an end!  sharepoint 2007 profile import stuck on enumerating
Remedy is simple! Just restart Office SharePoint service service! here is how:
  • Login to your App server, where Search service is running
  • Go to Start >> Administration Tools >> Services (or go to: Run >> type "Services.msc")
  • Right click on "Office SharePoint Server Search" >> choose Restart 
  • Optionally, You may have to do an IISReset!
This should end up the profile import job in stuck.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Hide All Responses from End Users in SharePoint Survey

Requirement:  Don't show all responses in a SharePoint survey to End-users! Only the Administrators should get all responses. 

Solution:
Go to Survey Settings >> Advanced Settings >> Set the Item-level Permissions as: Read access & Edit access to:  Only their own. This will hide all responses in SharePoint survey.
sharepoint survey hide results
SharePoint survey hide responses
End-users will get "Contributor" access to respond SharePoint Surveys. So, this setting will restrict them by getting the responses of other users. However this setting will not control Administrators, so they'll get to see all responses.

The above trick is applicable to both SharePoint 2007 and SharePoint 2010 survey to hide responses.

Another Way (for MOSS 2007):
Edit the Survey's overview.aspx (Site Actions >> Edit Page), in List view web part, choose "Modify Shared Web Part" and then set the "Selected View" as "Summary View". This will hide the link "Show a graphical summary of responses" from the page and display only total number of responses.sharepoint survey hide all responses
Revert the above change by changing "Selected view" to get the "Show a graphical summary of responses" link back in survey page. If you want Admin's to get all results in graphical view, create a new view and secure it.
 sharepoint 2007 survey hide results
Related links:


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, April 16, 2013

Disable "Save" Button Until User Selects "I Agree"

Requirement is: Don't allow the end user to submit a record until they Agree with the terms and conditions by selecting "I Agree".

So, we've to disable "Save" button until the "I Agree" check box is checked! Here is the jQuery script to achieve the same. Just place this code in your custom list form or in Content Editor Web Part (Place it in a Text file, upload and specify the script in CEWP).

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>

<script language="javascript">

$(document).ready(function(){
 //Disable the "Save" button initially
  $("input[value$='Save']").attr('disabled', true);  

 //alert('jQuery Works');


 //Enable-Disable "Save" button based on "I Agree" checkbox value!
   $("input[title$='Agree to Delete this site']").click(function(){
        if(this.checked)
           {
            $("input[value$='Save']").attr('disabled', false);
           }      
        else
           {
            $("input[value$='Save']").attr('disabled', true);  
           }
     }); 

  });

</script>
Code in action: If  "I Agree" check box isn't enabled:

After selecting  "I Agree" check box: Save button enabled!



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Rename Files / Find and Replace File Names in SharePoint Document Library with PowerShell

Here is the PowerShell script to rename all files in bulk in SharePoint library:
 
 #Get the Web  
 $Web = Get-SPWeb "http://sharepoint.crescent.com"

 #Get the List
 $List = $Web.Lists["Design Documents"]
            
 #Iterate Through All List Items
  foreach($ListItem in $List.Items)
    {
      if($null -ne $ListItem.File) #Exclude Document Sets
        {
              Write-Host "Checking $($ListItem.Name)..."
              #Check out, if Require checkout is enabled
              #$ListItem.File.CheckOut()
              #Replace "Crescent" with "Crescent Inc."
              $ListItem["Name"] = $ListItem["Name"].replace("Crescent","Crescent Inc.")
              #Update the changes
              $ListItem.Update()
              #$ListItem.File.CheckIn("Updated the File Name")
        }
    }


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, April 9, 2013

Add Web Application User Policy using PowerShell in SharePoint

PowerShell code snippet to Add new user in web application policy:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables
$WebAppURL = "http://sharepoint.crescent.com"
$UserID = "Global\EricConnell"
$UserDisplayName = "Global CIO"

#Get the Web Application
$WebApp = Get-spwebapplication $WebAppURL

#Convert the UserID to Claims - If your Web App is claims based!!!
if($WebApp.UseClaimsAuthentication)
{ 
 $UserID = (New-SPClaimsPrincipal -identity $UserID -identitytype 1).ToEncodedString()
}

#Crate FULL Access Web Application User Policy
$ZonePolicies = $WebApp.ZonePolicies("Default")
#Add sharepoint 2010 web application user policy with powershell
$Policy = $ZonePolicies.Add($UserID,$UserDisplayName)
$FullControl=$WebApp.PolicyRoles.GetSpecialRole("FullControl")
$Policy.PolicyRoleBindings.Add($FullControl)
$WebApp.Update()

Write-Host "Web Application Policy for $($UserDisplayName) has been Granted!"
GetSpecialRole() function in SharePoint 2010 can take enumerations from : [Microsoft.SharePoint.Administration.SPPolicyRoleType], Such as: FullControl, FullRead, etc.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, April 8, 2013

Change SharePoint 2010 Authentication from Classic Mode to Claims Based

As SharePoint 2013 requires claims authentication for most of its functionalities like Office web Apps, its mandatory to migrate to claims if your SharePoint 2010 is using classic mode authentication.

Migrate from classic-mode to claims-based authentication in SharePoint Server 2010 with PowerShell
PowerShell can help to convert classic mode authentication to claims based authentication for SharePoint 2010. Here is the script:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebAppURL = "http://sharepoint2010.crescent.com/"
$accountid = "crescent\SPAdmin"

#Get the web application
$WebApp = Get-SPWebApplication $WebAppURL
#convert classic mode authentication to claims based authentication sharepoint 2010
$WebApp.UseClaimsAuthentication = $true
$WebApp.Update()

$account = (New-SPClaimsPrincipal -identity $accountid -identitytype 1).ToEncodedString()
#Crate FULL Access Web Application User Policy
$ZonePolicies = $WebApp.ZonePolicies("Default")
$Policy = $ZonePolicies.Add($account,"PSPolicy")
$FullControl=$WebApp.PolicyRoles.GetSpecialRole("FullControl")
$Policy.PolicyRoleBindings.Add($FullControl)
$WebApp.Update()

#Migrate users from Classic to Claims
$WebApp.MigrateUsers($true)
$WebApp.ProvisionGlobally()
Best practice: In SharePoint 2010, change classic mode authentication to claims-based authentication first, and then migrate SharePoint 2010 to SharePoint 2013.

Switch from classic to claims-based authentication during backup-restore:
This is also applicable when you export-import or backup-restore sites between different web applications where the source web application uses Classic Authentication but the destination web application is configured to use Windows Claims!
Change SharePoint Authentication from Classic Mode to Claims Based

How to Check the web application's authentication mode:
Go to Central Administration >> Manage web applications and click on the site you’re planning to enable CBA. Under Web Applications tab click on the Authentication Providers icon and a small window will pop-up with "Claims Based Authentication"

You can also Try the PowerShell cmdlet:
(Get-spwebapplication "http://sharepoint2010.crescent.com").UseClaimsAuthentication

If you are migrating from classic-mode to claims-based authentication in SharePoint 2013, use: Convert-SPWebApplication cmdlet as in : http://technet.microsoft.com/en-us/library/gg251985%28v=office.15%29.aspx

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint 2010 Permission Levels - Explained

Users and groups must be granted some level of permission to get access to SharePoint sites. Which can be in one of two ways:
  1. Add the user directly to the SharePoint site/list/list item with specific permission level
  2. Add the user or security group to a SharePoint group (which is already assigned with a particular permission level)
What is permission levels in SharePoint?
Permission levels are set of permissions that a particular user or group is allowed to perform specific actions. Each permission levels consist of a number of detailed permissions (such as: Create Alerts, Delete Items, etc). SharePoint Server 2010 provides these default permission levels:  Full Control, Design, Contribute, Read (Sorted highest permission level to the lowest).

Why we need permission levels in SharePoint? Security! It defines who can do what. The level of access is controlled by the permission level, which you can think of as a security role.

SharePoint 2010 default permission levels:
  • Read - Users Can Open & view SharePoint content including documents, pictures and lists. They'll not be able to create, modify, or delete.
  • Contribute - Allows the user to view, add, update, and delete content
  • Designer - Can do everything contributors do. Plus create new document libraries, columns, views, as well as change the layout of the website by adding or moving web parts.
  • Full Control - Users can perform any action in the site, including adding/deleting members and changing their access.
  • View Only: Users can view web pages, lists, and list items but can't download.
In addition with above permission levels for Team Sites template,  we get three more with Publishing site templates,:
  • Approve - Users may approve pages, list items, or documents submitted by others.
  • Manage Hierarchy - Users may edit pages, list items, and documents. Manage Hierarchy permissions also allow the users to create sites.
  • Restricted Read - Users may view pages and documents; however, historical versions are not available.


SharePoint 2010 Permission Level FAQs:


What is limited access permission level in SharePoint?
Limited Access is a special type of security role that a user or group is automatically granted when
getting access to a specific list/library/item, but not to the site itself.

E.g. When we grant access to a specific list, but not the site, users will get read access to the list and limited access to the site. Because user must get access to the site in order to access the list, isn't it?


SharePoint permission level scope: Permission Level are scoped at Site Collection (You can't define it at web level) . add a permission level ribbon button is missing SharePoint 2010. If you Break the Inheritance, will get Permission levels but will not be able to customize it at subsite level as permission levels greyed out in subsites.

SharePoint permission level inheritance: Permission levels are created at CA/site collection level (in RootWeb) and inherited by its subsites. Each site collection has its own set of default permission levels. When you change or add new permission levels, they will be automatically replicated to all subsites in the site collection.

To Get all permission levels in SharePoint 2010:
  • Log on to your SharePoint site collection as a site owner
  • From Site Settings, click on Site Permissions under Users and Permissions. 
  • In the ribbon click on Permission Levels. You will see all the different permission levels for the site collection.
SharePoint 2010 Permission Levels

How to add new permission level in SharePoint 2010:
Refer my another post to add new permission level in SharePoint How to Create Custom Permission Level in SharePoint 2010 Its a best practice: Not to change the out-of-the-box permission levels. Always Create a permission level by copying existing permission level and add/remove the base permissions.

MSDN Reference to Edit, create, and delete permission levels:
http://office.microsoft.com/en-001/sharepoint-server-help/edit-create-and-delete-permission-levels-HA101805381.aspx


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, April 6, 2013

Show or Hide SharePoint List Form Fields based on Another Field's Value using JQuery

What: Show or Hide a SharePoint list form field based on an another field's value.

How: Use jQuery script to show/hide the dependent field from list form based on current field's value.

Code:
//Place this code just below the place holder "PlaceHolderMain" in Custom List Form. 
<script type="text/javascript" src="/_layouts/1033/jquery-1.4.4.min.js"></script> //Or Get refer it from "http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"
<script type="text/javascript">
 $(document).ready(function()
  {
     //alert('jQuery Works');

      //Hide Reason fields initially 
      $("textarea[title$='Question2Reason']").parent('span').parent('td').parent('tr').hide();

     //Associate a function with Drop down change event
  $("select[title$='Question 2:']").change(function()
      {
        if($(this).val()=='Yes')
         {
           $("textarea[title$='Question2Reason']").parent('span').parent('td').parent('tr').show();
         }
        else
         {
   $("textarea[title$='Question2Reason']").parent('span').parent('td').parent('tr').hide();
         }
     });
 });
</script>
and the output: No value selected
Show or Hide SharePoint List Form Fields based on Another Field's Value using JQuery
Reason filed visible on selecting the drop down value as: Yes
Reason filed is hidden on selecting the drop down value as: No


Instead hide, If you want to Disable/Enable Fields, Use this code:
 if($(this).val()=='Yes')
         {
           $("textarea[title$='Question2Reason']").attr('disabled', false);
         }
        else
         {
   $("textarea[title$='Question2Reason']").attr('disabled', true);
         }

Related post: Disable "Save" Button Until User Selects "I Agree"


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, April 4, 2013

The server may not have Microsoft SharePoint foundation installed, your machine's IP address may not have access to the server, or you may have specified an invalid proxy server (HTTP Error 403)

Problem:  Tried opening a SharePoint 2013 site in SharePoint Designer 2013 and got this error message "The server may not have Microsoft SharePoint foundation installed, your machine's IP address may not have access to the server, or you may have specified an invalid proxy server (HTTP Error 403)"
The server may not have Microsoft SharePoint foundation installed, your machine's IP address may not have access to the server, or you may have specified an invalid proxy server (HTTP Error 403)
Root cause is: The particular SharePoint site is published with TMG! SharePoint Designer 2013 couldn't pass the credentials to TMG and resulted in HTTP 403 Error.

Solution: Open your SharePoint site in Web browser, Login to Site once. Now, Restart SharePoint designer and try to open your site with SharePoint designer and you should be able to get the site.


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, April 3, 2013

Create Form Library in SharePoint using PowerShell

Requirement: Create form library in SharePoint using PowerShell.

Here is the SharePoint PowerShell script to create form library:
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

Function Create-FormLibrary 
{
 Param
 ( 
  [Microsoft.SharePoint.SPWeb]$Web,
  [String] $ListName,
  [String] $Description
 )
 #Get the Form Library template
 $ListTemplate = [Microsoft.Sharepoint.SPListTemplateType]::XMLForm
 
 #Check if the list already exists
 if( ($web.Lists.TryGetList($ListName)) -eq $null)
 {
  #Create the list
     $Web.Lists.Add($ListName,$Description,$ListTemplate) 
  
  #You can Set Properties of Library such as OnQuickLaunch, etc
  $FormLib = $Web.Lists[$ListName] 
  $FormLib.OnQuickLaunch = $true
  $FormLib.Update()
  
  Write-Host "Form library created successfully!"
 }
 else
 {
  Write-Host "Form library already exists!"
 }
 #Dispose web object
    $Web.Dispose()    
}

#Get the Web
$web = Get-SPWeb "http://sharepoint.crescent.com/contact-us/"

#Cal the function to create library
Create-FormLibrary $web "ContactUsForms" "Form Library to store Contact us Forms"


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Branding SharePoint 2010 Top Navigation Dropdown Menu Bar

By default SharePoint 2010 Top Navigation menu looks like the below screen without branding.
sharepoint 2010 top navigation branding
The Top Navigation Menu is the primary object in SharePoint user interface. We can customize top navigation menu's look and feel by overriding CSS styles. Here, I'm Sharing the CSS code and screens for reference, from my recent project.

SharePoint 2010 Top Navigation & Flyout Menu CSS Style:
/*** Top Navigaion Global Menu Container ***/
 .s4-tn
{
      padding: 0px;
      margin: 0px;
      font-family: 'Calibri' !important;
      font-size: 11pt !important;
      padding-left: 10px;
}

/*** Top Navigaion Static Menu Style ***/
.s4-tn li.static > .menu-item
{
      color: #5A9A18;
      border: 1px solid transparent;
      padding: 4px 10px;
      line-height: 25px;
      height: 25px;
}

/*** Top Navigaion Static Menu Hover ***/
.s4-tn li.static > a:hover
{
      background: url("/_layouts/Images/selbg.png") repeat-x left top;
      background-color: #529610;
      color: #fff;
      text-decoration: none;
}

/*** Top Navigaion Static Menu Selected ***/
.s4-toplinks .s4-tn a.selected
{
      background: url("/_layouts/Images/selbg.png") repeat-x left top;
      background-color: #529610;
      color: #fff;
      text-decoration: none;
      border: 1px transparent solid;
      padding-right: 10px;
      padding-left: 10px;
      margin: 0px;
      border-color: #529610;
}

/*** Top Navigation Flyover/Dynamic Menu Container ***/
.s4-tn ul.dynamic {
 background-color: white;
 border: 1px solid #000;
}

/*** Top Navigation Sub-Menu Items Padding ***/
.s4-tn li.dynamic > .menu-item {
 padding: 10px 20px 10px 20px;
}

/***  Top Navigation Sub-Menu Items (HyperLinks) CSS Style ***/
.s4-tn li.dynamic > a {
 font-weight: normal;
 color: #529610;
}
/*** Top Navigation Sub-Menu Items (HyperLinks) Hover Style ***/
.s4-tn li.dynamic > a:hover {
 font-weight: bold;
 background-color: #AECE8F;
 color: #FFF;
}
Typically, Through CSS styles, we set background color, font, border, etc to apply branding in SharePoint 2010 top navigation menu.

Output of the above CSS:
sharepoint 2010 branding top menu
sharepoint 2010 change menu style
Not just colors, even images can be set in SharePoint 2010 horizontal menu branding customizations.

CSS Style for Branded SharePoint 2010 Top Navigation Menu (a bit variant from above):

/*** Top Navigaion Global Menu Container ***/
 .s4-tn
{
      padding: 0px;
      margin: 0px;
      font-family: 'Calibri' !important;
      font-size: 11pt !important;
      padding-left: 10px;
}

/*** Top Navigaion Static Menu Style ***/
.s4-tn li.static > .menu-item
{
      color: #21374C;
      border: 1px solid #93C2EC;
      padding: 4px 10px;
      line-height: 25px;
      height: 25px;
      background: url("/_layouts/Images/selbg.png") repeat-x left top;
      background-color:#47A4D3;
}

/*** Top Navigaion Static Menu Hover ***/
.s4-tn li.static > a:hover
{
      background: url("/_layouts/Images/selbg.png") repeat-x left top;
      background-color: #0A85C4;
      color: #fff;
      text-decoration: none;
}

/*** Top Navigaion Static Menu Selected ***/
.s4-toplinks .s4-tn a.selected
{
      background: url("/_layouts/Images/selbg.png") repeat-x left top; /* Glass Effect Shade Image */
      background-color: #0A85C4;
      color: #fff;
      text-decoration: none;
      border: 1px transparent solid;
      padding-right: 10px;
      padding-left: 10px;
      margin: 0px;
      border-color: #134072;
}

/*** Top Navigation Flyover/Dynamic Menu Container ***/
.s4-tn ul.dynamic {
 background-color: #D5E4F2;
 border: 1px solid #000;
}

/*** Top Navigation Sub-Menu Items Padding ***/
.s4-tn li.dynamic > .menu-item {
 padding: 10px 20px 10px 20px;
}

/***  Top Navigation Sub-Menu Items (HyperLinks) CSS Style ***/
.s4-tn li.dynamic > a {
 font-weight: normal;
 color: #0189FA;
}
/*** Top Navigation Sub-Menu Items (HyperLinks) Hover Style ***/
.s4-tn li.dynamic > a:hover {
 font-weight: bold;
 background-color: #61CBFD;
 color: #FFF;
}
and the output:
sharepoint 2010 top menu navigation css
The custom CSS can be placed in a Style Sheet and Linked in Master page, or it can be uploaded to SharePoint library/file system and set as Alternate CSS Style sheet under site settings.

MSDN Reference: http://msdn.microsoft.com/en-us/library/gg430141%28v=office.14%29.aspx

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, April 2, 2013

Grant Permission to Folders in SharePoint Document Library using PowerShell

Requirement: grant folder permission in SharePoint using PowerShell script.

Here is my script to grant access to a folder in SharePoint Library using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function Set-FolderPermissions($webUrl, $FolderURL, $UserAccount, $PermissionLevel)
{
    #Get Web
    $web = Get-SPWeb $webUrl   
    #Get the User   
    $user = $web.EnsureUser($UserAccount)
    #Get the Permission Level
    $RoleDefinition = $web.RoleDefinitions[$PermissionLevel]
 
    #Get the Folder    
    $Folder = $web.GetFolder($FolderURL).Item
    if ($Folder -ne $null) 
    {  
        #Check if Item has Unique Permissions. If not, Break the inheritance
        if($folder.HasUniqueRoleAssignments -eq $false) 
        {
            $folder.BreakRoleInheritance($true) 
        }

        #Grant Permissions
        $RoleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
        $RoleAssignment.RoleDefinitionBindings.Add($RoleDefinition) 
        $Folder.RoleAssignments.Add($RoleAssignment)
        $Folder.SystemUpdate(); 

        Write-Host "Successfully added $($user) to folder $($Folder.Name)" -foregroundcolor Green
    }

}

#Variables
$WebURL="http://intranet.crescent.com/"
$FolderURL="http://intranet.crescent.com/Sales/Documents/Proposals"
$UserAccount="i:0#.w|Crescent\salaudeen"
$PermissionLevel="Read"

#Call the function to Grant permission to a folder
Set-FolderPermissions $WebURL $FolderURL $UserAccount $PermissionLevel

Set Permission to SharePoint Group to All Folders in a Library:
Certain folders in a SharePoint library is with unique permission. Requirement is to add permission to a SharePoint group to all folders with unique permissions.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

### Variables ###
#Site URL and List names
$SiteURL = "http://intranet.crescent.com/support"
$ListName = "Documents"                 

#Get site and List objects
$web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)
$GroupName = "Support Visitors"
$PermissionLevel = "Read"

    if ($list -ne $null) 
    {  
       $Foldercoll=$List.Folders | Sort-Object Name

        #Loop through each Item in the List
         foreach($folder in $Foldercoll)
        {
                #Check if Item has Unique Permissions.
                if($folder.HasUniqueRoleAssignments -eq $true) 
                { 
                    #Grant Access
                    if ($web.SiteGroups[$GroupName] -ne $null) 
                    {
                        #Get the Group from GroupName Parameter 
                        $group = $web.SiteGroups[$GroupName] 
                        $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group) 

                        #Get Permission Level, such as "Read", "Contribute", etc
                        $roleDefinition = $web.RoleDefinitions[$PermissionLevel]
                        $roleAssignment.RoleDefinitionBindings.Add($roleDefinition); 
                        
                        #Grant Access to specified Group
                        $folder.RoleAssignments.Add($roleAssignment) 
                        #To Remove Access: Call  $item.RoleAssignments.Remove($group) . No Need for objects: roleAssignment, roleDefinition
                        $folder.SystemUpdate(); 
                        Write-Host "Successfully added $($PermissionLevel) to $GroupName group in $($Folder.Name)" -foregroundcolor Green 
                    }
                }
        }
    } 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, April 1, 2013

SharePoint "NT AUTHORITY\Authenticated Users" - FAQs

Who are AUTHORITY\Authenticated Users in SharePoint?
Every user Account that can logon to your network! So, If you want all of your AD users to access a SharePoint site, Grant access to "NT AUTHORITY\Authenticated Users" to the relevant SharePoint group. 'NT Authority\Authenticated Users' can also be used to grant access to users from multiple domains of your network.

Adding NT Authority\Authenticated Users to SharePoint

In SharePoint 2007, There was an easy way to add "NT AUTHORITY\Authenticated Users" by clicking "Add All Authenticated Users" link. But its removed in SharePoint 2010.

SharePoint 2010 "NT Authority\Authenticated Users" Missing
SharePoint 2010 "NT Authority\Authenticated Users" is not available from Address Book.
SharePoint 2010 "NT Authority\Authenticated Users" Missing
In SharePoint 2010, Microsoft Removed the NT AUTHORITY\Authenticated Users from Global Address book, so you will not find it there. But you have to type it MANUALLY into the names box and then hit resolve icon next to it. To Add all users to SharePoint site:
  • Click Site Actions >>  Site Permissions.
  • Click Grant Permissions.
  • In Select Users, enter "NT AUTHORITY\Authenticated Users"
  • Select the relevant SharePoint group and Click "OK"
Its also possible to Add under Web Application Policy with permission levels like Full control, contribute, Read, etc.
Add NT Authority\Authenticated Users to SharePoint
Remove "NT Authority\Authenticated Users" from SharePoint
Like any other user account, you can delete "NT Authority\Authenticated Users" from SharePoint.
  • Go to Site Actions 
  • Site Settings 
  • Click on "More..." from Quick Launch 
  • Select the "NT AUTHORITY\authenticated users" user 
  • Click on "Delete User from Site Collection" to disable "NT Authority\Authenticated Users" from SharePoint site collection.
Add "NT Authority\Authenticated Users" programmatically in SharePoint:
How to add programmatically “every user” group to a Sharepoint Site
    //Get the Reader Permission Level
    SPRoleDefinition readerRole = web.RoleDefinitions.GetByType(SPRoleType.Reader);

    SPUser allusers = web.EnsureUser("NT AUTHORITY\\Authenticated Users");

    SPRoleAssignment spRoleAssignment = new SPRoleAssignment(allUsers);
    spRoleAssignment.RoleDefinitionBindings.Add(readerRole);

    web.RoleAssignments.Add(roleAssignment); 
    web.Update();


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Rename SharePoint Column Programmatically

Here is how we can rename SharePoint list or site field or column programmatically with PowerShell and C# object model code:

PowerShell Code to Rename a SharePoint Field:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$Web= Get-SPWeb "http://sharepoint.crescent.com"

#Get the "Risk Metrics" List
$list= $web.Lists.TryGetList("Risk Metrics")

#Get "Project Name" Field
$field = $list.fields | where {$_.Title -eq "Project Name"}

#Set Field Display Name and Update
$field.Title ="Program Name"
$field.Update()

Rename a SharePoint Field Programmatically (C#):

           using(SPSite site=new SPSite("http://sharepoint.crescent.com"))
            {
                //Get the "Risk Metrics" List
                SPList list = site.RootWeb.Lists["Risk Metrics"];

                //Get "Project Name" Field
                SPField field = list.Fields["Project Name"];

                //Set Field Display Name and Update
                field.Title = "Program Name";
                field.Update();

                //You can also use: list.Fields["Project Name"].Title = "Project Name";
               //list.Update();                 
            } 

PowerShell to change field display name in SharePoint site collection:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -EA SilentlyContinue

#Variables
$SiteURL = "http://sharepoint.crescent.com/"
$OldColumnName ="Department"
$NewColumnName ="Entity"

#Get the Site
$site = Get-SPSite $SiteURL

 #Iterate through each web (Sub-Site)
 foreach ($web in $site.AllWebs)
 {   
  #Array to Hold Lists with specific column
  $ListsToProcess= @()
  #Get All Lists
  $Lists = $web.Lists
  #ITerate through each list
     foreach ($list in $lists)
     {
   #Iterate through each column
         foreach ($column in $list.Fields)
         {
    #Check for the specific column
             if ($column.Title -eq $OldColumnName)
             {
     Write-Host "Found the Column in list: " $list.Title " at "$web.Url
     #Send it to an Array
     $ListsToProcess+=$List
             }
         }
     }
  
  #Process each list and rename the columns
  foreach ($list in $ListsToProcess)
     {
   #Get the Old column by its name
   $column = $list.fields | where {$_.Title -eq $OldColumnName}
   
   #rename sharepoint list column powershell
   $column.Title = $NewColumnName
   $column.Update()
  }
  $web.Dispose()
 }
$site.Dispose()


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SMTP4DEV - SMTP Server Tool to Test SharePoint 2013 Ougoing E-Mails

What is SMTP4DEV?
Well, SMTP4Dev is a nifty tool for capturing and testing Emails from any application. It doesn't actually send any Emails to actual recipient, but it captures Emails triggered from applications such as SharePoint. Here is how we can utilize this tool for testing outgoing Emails from SharePoint.

This is extremely helpful in development environments and for testing purposes.

Step 1: Download SMTP4DEV tool from Codeplex
Download the SMTP4DEV tool from codeplex: https://smtp4dev.codeplex.com/ Standalone also available.! Just click and run the tool.

Step 2: Set Domain name in the tool
This tool runs from system tray area. The first thing you have to set is: configure the domain name as your current server name (by default it will be localhost). 
  • Go to options >> Under the Server tab, set the domain name accordingly.
    smtp4dev sharepoint 2010

Step 3: Configure the Outgoing Email settings in Central admin
Now in SharePoint 2013 (or in SharePoint 2010), set the outgoing email settings from SharePoint central administration site.
  • Central Administration >> System Settings >> Configure outgoing e-mail settings >> add the same machine name in smtp4dev
    smtp4dev sharepoint 2013
Make sure that the domain name provided in smtp4dev tool and the Outgoing Email settings in SharePoint central Admin are same.

Step 4: Write code / Set Alerts in SharePoint to trigger E-mails
Now, You can write your custom code/event receiver/workflow/Create alerts to send Emails from SharePoint. Here is my sample code to trigger Email with SPUtililty.SendMail using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$siteUrl ="http://intranet.crescent.com"

$Web = Get-SPWeb $siteURL
 
$mail = [Microsoft.Sharepoint.Utilities.SpUtility]::SendEmail($web,0,0,"salaudeen@crescent.comn","Subject of the Mail","mail body")

Here is the output:
As soon as an Email triggered from SharePoint, This tiny tool starts blinking and you should see messages appear in SMTP4Dev!
smtp4dev sharepoint
You can inspect the Email from the tool and open mails with any Email client such as Outlook.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...