Posts

Powershell To Attach workflow on Content Type and create Retention Policy on it - SharePoint 2013

Hi Friends, I got a requirement to create retention policy on Content type and action is to start workflow. as well attach workflow to the content type. I choose to go with powershell. save the following code into file called SetupRetentionPolicy.ps1 call like: c:\>.\SetupRetentionPolicy.ps1 -url <weburl> -ContentTypeName <Contenttype> param( $url=$null, $ContentTypeName=$null) $site = get-spsite $url $web = $site.openweb() Enable-SPFeature –identity "LocationBasedPolicy" -URL $url -ErrorAction SilentlyContinue $Property = "Modified" $Period = 1; $PeriodType = "years" function AddWorkflowToContentType($site, $ctName, $WfName, $WfAssociationName, $TaxTaskList) { [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SharePoint') [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Office.Policy') [Guid]$wfTemplateId = New-Object Gui...

How to: Follow documents and sites by using the .NET JavaScript object model in SharePoint 2013

Scenario is here we will create one sample user control, which will have simple one star which we can place on our page to follow the site/documents using JavaScript object model. 1. Visual Studio 2012, SharePoint project. 2. Add new item, web user control and give a name : favoriteControl.ascx 3. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FavoriteControl.ascx.cs" Inherits="test.FavoriteControl" %> <div class="favIcon" runat="server" id="favoriteLink"><a href="#" runat="server" id="favorite" onclick="javascript:Follow();"></a></div> 4. Add Script file to project, named favoritehelper.js and paste the following code: $(document).ready(function () { // Ensure that the SP.UserProfiles.js file is loaded before the custom code runs. //SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'sp.userprofiles...

SharePoint 2013 Workflow gets canceled automatically

Hi, I was struck with the error of Workflow gets canceled automatically. Scenario was : A new SP 2013 installation, one server with SP, WF, etc and the other is simply SQL Server. Went through the installation steps for Workflow including the powershell bits. In designer, I am able to create a simple workflow and select 2013 as the type. When the workflow is run, is shows internal status is canceled and has the following error text below. RequestorId: 55c6990b-c4a6-352c-4a5b-449fc1aecac4. Details: System.ApplicationException: HTTP 401 {"x-ms-diagnostics":["3001000;reason=\"There has been an error authenticating the request.\";category=\"invalid_client\""],"SPRequestGuid":["55c6990b-c4a6-352c-4a5b-449fc1aecac4"],"request-id":["55c6990b-c4a6-352c-4a5b-449fc1aecac4"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"SPRequestDuration":["61"],"SPIisLatency":["1...

SharePoint 2013 Taxonomy import using .csv and Setting site navigation to use taxonomy using PowerShell

Image
Now requirement to import taxonomy from .csv file using PowerShell as well set taxonomy as site navigation with url. 1. Create .csv file 2. Create new script and paste below code. Param( [string] $siteUrl = $(throw "Error: Parameter siteUrl is required"), [boolean]$emptyfirst ) ##Variables that should not be edited $termsetName="My Navigation" function CreateTerm( $parent, $name, $url ) { Write-Host "Adding term $($parent.Name) -> $name" $term = $parent.CreateTerm("$name", 1033) $term.IsAvailableForTagging = $false $term.SetLocalCustomProperty("_Sys_Nav_ExcludedProviders", '"CurrentNavigationTaxonomyProvider"') $term.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", $url) #$term.SetLocalCustomProperty("tIME", $url) return $term } function GetTerm($termName, $parent) { $termName = [Microsoft.SharePoint.Taxonomy.TaxonomyI...

SharePoint 2013 TermSet with PowerShell

Create new script with following code: $session = Get - SPTaxonomySession - Site "Your site Url" $termStore = $session . TermStores [“ Managed Metadata Application ”] - change your managed metadata service name $group = $termstore . CreateGroup (“ My New Group ”) $group . Description = "My Term Group" $termStore . CommitAll () $termSet = $group . CreateTermSet (“ My TermSet ”, 1033 ) $termSet . Description = “ My TermSet ” $termSet . IsAvailableForTagging = $true $termSet . IsOpenForTermCreation = $true $termStore . CommitAll () To enable the term set for navigation, i.e    "Use this Term Set for Site Navigation"   use following code to make it enabled. $navigationSet = $group . CreateTermSet ( $termsetName ) $navigationSet . SetCustomProperty ( "_Sys_Nav_IsNavigationTermSet" , "True" ) $navigationSet . SetCustomProperty ( "_Sys_Nav_AttachedWeb_SiteId" , $site . ID . ToString ...

Remove sharepoint site and custom list from the search result

Image
Today, I came across the requirement where I have to stop site to be crawl in search Go to the  Site Actions=> Site Settings => Site Administration => Search and offline availability. We can manage the visibility of site and site's web page's web parts for search. Using SharePoint object model: Using Powershell: #---------StopSearch $site=Get-SPSite "http://servername:1111/" $web=$site.RootWeb; $web.AllowAutomaticASPXPageIndexing=$true $web.ASPXPageIndexMode=[Microsoft.SharePoint.WebASPXPageIndexMode]::Never $web.NoCrawl=$false $web.Update() #---------StartSearch $site=Get-SPSite "http://servername:1111/" $web=$site.RootWeb; $web.AllowAutomaticASPXPageIndexing=$false $web.ASPXPageIndexMode=[Microsoft.SharePoint.WebASPXPageIndexMode]::Never $web.NoCrawl=$true $web.Update() For SharePoint Custom list: Go to :  List Settings page, under  General Settings , click  Advanced settings . In the  Search  section, under  Allow items from...

Custom aspx page with default master page in SharePoint

I had a requirement to create custom aspx page and deploy to _layouts folder. Got help from this  http://www.codeproject.com/Tips/312544/How-To-Add-Custom-ASP-NET-Page-Using-Layouts-Folde Page is deployed to _layouts folder. Code in .aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ItemDetails.aspx.cs" Inherits="namespace,Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ffee3a64ae3d939" Debug="true" MasterPageFile="~/_layouts/v4.master" %> <%@ Assembly Name="Microsoft.SharePoint.ApplicationPages,  Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderMain" runat="server">    main file content </asp:Content> <asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server"> </asp:Content...