kwizcom banner advertisement

Empty SharePoint Recycle Bins Programmatically with PowerShell

7:12 PM    , , , , ,
Requirement: Empty recycle bin in SharePoint In a Database attachment method migration project, we decided to clear all the recycle bins to get some additional free space in databases. There were 3000+ site collections. Automation? SharePoint Automation = PowerShell  :-) Empty SharePoint Site Collection Recycle bin using PowerShell: Here is the PowerShell script to empty SharePoint recycle bin. #Get the Site Collection $Site = Get-SPSite "https://portal.crescent.com/sites/test" #Delete all from 1st Stage Recycle bin $Site.AllWebs | Foreach-object { $_.RecycleBin.MoveAllToSecondStage() } #Empty 2nd Stage Recycle bin $Site.RecycleBin.DeleteAll(); PowerShell Script to Empty SharePoint Recycle Bins Programmatically: Lets empty the recycle bin of all site collection under a given web application using PowerShell. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $WebApp=Get-SPWebApplication "http://intranet.crescent.com" f
Empty SharePoint Recycle Bins Programmatically with PowerShell Empty SharePoint Recycle Bins Programmatically with PowerShell Reviewed by Salaudeen Rajack on 7:12 PM Rating: 5

Create Shortcut in SharePoint Document Library

2:55 PM    , ,
Requirement is to create a Shortcut link inside SharePoint document library. OK, Tried uploading the URL shortcut (.url) file, and got the error message saying " The following file(s) have been blocked by the administrator: URL Shortcut.url ". Solution: Add "Link to a Document" content type to the document library. Here is how to create shortcut in SharePoint document library: Create Shortcut in SharePoint Document Library : 1. Go to Library Settings >> Advanced Settings. 2. Enable "Allow management of content types" option and click OK 3. In Library settings page, click on Content Types and click "Add from Existing Site content types" link. 4. Choose "Link to a Document and click on "Add >" button, then OK. 5. Now create a New entry based on "Link to a Document", Enter the description & URL You are done!   Drawback: The above method will not work when you move from HTTPS to HTTP
Create Shortcut in SharePoint Document Library Create Shortcut in SharePoint Document Library Reviewed by Salaudeen Rajack on 2:55 PM Rating: 5

Creating Dependent Features in SharePoint

2:21 PM    ,
In a recent project, had to create a feature which provisions bunch of Lists, Libraries and Pages with custom web parts. Those custom web parts also deployed as feature based solutions. So the requirement is: Activate the features which brings the custom web parts first, and then activate the feature which creates the pages with custom web parts. Problem: If the user tries to activate the Main feature- which creates web part pages with custom web parts, with out activating a feature which brings the custom web part: Boom - Error! Here comes the solution: Feature Activation dependency! How to Implement? Simple! just include the  <ActivationDependencies> in Feature.xml <?xml version="1.0" encoding="utf-8"?> <Feature Id="2cec1d22-290f-41b2-a14b-164a82d43b04" Title="Crescent Project Site Template" Description="Feature for Crescent project site Template" Version="12.0.0.0"
Creating Dependent Features in SharePoint Creating Dependent Features in SharePoint Reviewed by Salaudeen Rajack on 2:21 PM Rating: 5

Install Features Programmatically in SharePoint

8:21 PM    , ,
Generally, we use STSADM command line to Install features by STSADM –o installfeature –name FeatureName . or Install-SPFeature PowerShell Cmdlet. At times, we may have to execute stsadm programmatically to install a Feature. Say for e.g. from console applications or from another feature activation code.  Here is how it can be achieved. Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using System.Diagnostics; namespace InstallFeature { class Program { static void Main(string[] args) { string site; if (args.Length == 0) { Console.WriteLine("Enter the Web Application URL:"); site = Console.ReadLine(); } else { site = args[0]; } SPSite tmpRoot = new SPSite(site); //Get the particular
Install Features Programmatically in SharePoint Install Features Programmatically in SharePoint Reviewed by Salaudeen Rajack on 8:21 PM Rating: 5

How to Create Site Columns Programmatically in SharePoint?

7:06 PM    , , ,
Requirement: Add Site columns to the SharePoint site programmatically as part of a site provisioning code. Code to Add a New Site column to SharePoint Site:   using (SPSite site = new SPSite("http://sharepoint.com")) { SPWeb web = site.RootWeb; //Add Site Column //Add choice Field "Operating Country" if (!web.Fields.ContainsField("Operating Country")) { string countryField=web.Fields.Add("Operating Country", SPFieldType.Choice , false); //Set the Field Properties SPFieldChoice OperatingCountry = (SPFieldChoice)web.Fields.GetField("Operating Country"); //Set the group for the Site column OperatingCountry.Group = "Crescent"; //Add the choices string
How to Create Site Columns Programmatically in SharePoint? How to Create Site Columns Programmatically in SharePoint? Reviewed by Salaudeen Rajack on 7:06 PM Rating: 5

Deploy Custom List templates(.stp) as Feature based Solution in SharePoint

2:45 PM    , ,
Requirement : Had a custom List template, and wanted to make it available in create page of all sites of the site collection. Solution:   How to deploy SharePoint list template? Create a WSP builder solution to deploy the .stp file to the List template gallery of required site collections! Just create a Feature with the below element.xml file. Add the .Stp file to the solution. Here is Elements.xml file: <?xml version="1.0" encoding="utf-8" ?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="EnrollmentTemplate" List="114" Url="_catalogs/lt" RootWebOnly="TRUE"> <File Url="Enrollment.stp" Type="GhostableInLibrary"> <Property Name="LanguageDisplay" Value="English" /> <Property Name="Version" Value="3" /> </File> </Module> </Elements> Project Struct
Deploy Custom List templates(.stp) as Feature based Solution in SharePoint Deploy Custom List templates(.stp) as Feature based Solution in SharePoint Reviewed by Salaudeen Rajack on 2:45 PM Rating: 5

Delete Attachments from SharePoint List Items using Powershell

5:37 PM    , ,
There is a requirement to delete all the attachments named as "xyx.presales.document.docs" from a SharePoint List where 100's of list items already created with lot of attachments.  This requirement can be achieved with either SharePoint Object model or with PowerShell. Here is the script to programmatically delete the attachments based on its name. $web=Get-SPWeb -identity "http://sharepointsite.com" $list=$web.lists["Documents"] foreach($item in $List.Items) { for($i=$item.Attachments.count-1; $i -ge 0; $i--) { if($item.Attachments[$i].endswith("presales.document.docx")) { write-host "File Deleted:" $item.Attachments[$i] $Item.Attachments.Delete($item.Attachments[$i]) } } $item.update() }
Delete Attachments from SharePoint List Items using Powershell Delete Attachments from SharePoint List Items using Powershell Reviewed by Salaudeen Rajack on 5:37 PM Rating: 5

How to Add Web Parts to the Page Programmatically?

3:23 PM    , ,
Requirement is to add OOTB and Custom web parts to a web part page programmatically via features. I'm sharing the code snippets: To Add Out Of The Box Web Parts: (E.g. Content Query Web Part, Content Editor, Page Viewer Web Part, etc): SPWeb web = properties.Feature.Parent as SPWeb; //Create the SPLimitedWebPart Manager to Add web parts SPLimitedWebPartManager WebPartMgr = web.GetLimitedWebPartManager("Home.aspx", PersonalizationScope.Shared); //Add Project Matter Title CEWP ContentEditorWebPart ProjectDetailsTitleCEWP = new ContentEditorWebPart(); //Set the Properties of the CEWP ProjectDetailsTitleCEWP.Title = "Project Matters Title"; ProjectDetailsTitleCEWP.ChromeType = PartChromeType.None; //Create an XmlElement to hold the value of the Content property. XmlElement Pro
How to Add Web Parts to the Page Programmatically? How to Add Web Parts to the Page Programmatically? Reviewed by Salaudeen Rajack on 3:23 PM Rating: 5

SharePoint List Registration IDs Reference

1:26 PM    , ,
Reference Table for SharePoint List Registration ID: ID Name 100 Generic list 101 Document library 102 Survey 103 Links list 104 Announcements list 105 Contacts list 106 Events list 107 Tasks list 108 Discussion board 109 Picture library 110 Data sources 111 Site template gallery 112 User Information list 113 Web Part gallery 114 List template gallery 115 XML Form library 116 Master pages gallery 117 No-Code Workflows 118 Custom Workflow Process 119 Wiki Page library 120 Custom grid for a list 130 Data Connection library 140 Workflow History 150 Gantt Tasks list 200 Meeting Series list 201 Meeting Agenda list 202 Meeting Attendees list 204 Meeting
SharePoint List Registration IDs Reference SharePoint List Registration IDs Reference Reviewed by Salaudeen Rajack on 1:26 PM Rating: 5

Event Receivers vs Workflows - Decide Which One to Use

7:25 PM    , , ,
As SharePoint Event Receivers & SharePoint workflows have a lot of similarities, Many people stuck on deciding which one to go with: Event Receiver or Workflow? event receiver vs. workflow in SharePoint is always tricky to decide. Main Differences Between SharePoint Event Receivers and SharePoint Workflows are: 1. Event handlers Can't be manually initiated - workflows can be initiated either automatically or manually. 2. Event Handlers can be Synchronous or Asynchronous - Workflows are always async (They executes after the operation) 3. In Event Receivers we can cancel the operation (such as add/update/delete) - But in Workflows its not possible. 4. Event handlers execute from a Particular WFE, So when some thing goes wrong in that WFE, It may end-up. But Workflow Jobs are robust and  can resume even after Reboots. 5. Usually Event handlers runs for short period - Workflows can be longer even for years! 6. There is no User Interface/user Interaction in Even
Event Receivers vs Workflows - Decide Which One to Use Event Receivers vs Workflows - Decide Which One to Use Reviewed by Salaudeen Rajack on 7:25 PM Rating: 5

Get SharePoint Recycle Bin Storage Size

8:33 PM    , , , ,
In a Database attachment method migration project, wanted to get the insights on how much space being occupied by SharePoint Admin Recycle bin for all site collections. There were 3000+ site collections. PowerShell Script to get First Stage recycle bin size: function global:Get-SPSite($url) { return new-Object Microsoft.SharePoint.SPSite($url) } function Get-RecyclebinSize($SiteURL) { #Get the site collection $site = Get-SPSite $SiteURL # Create SPRecycleBinQuery object to Query Reycle bin $SPRecycleBinQuery = New-Object -TypeName Microsoft.SharePoint.SPRecycleBinQuery $SPRecycleBinQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::FirstStageRecycleBin # Set the query should return maximum number of objects $SPRecycleBinQuery.RowLimit = [int]::MaxValue-1 # Get the sum of values of the 'Size' property of all Recycle Bin items and assign it to a variable $RecycleBinSize = $site.GetRecycleBinItems($S
Get SharePoint Recycle Bin Storage Size Get SharePoint Recycle Bin Storage Size Reviewed by Salaudeen Rajack on 8:33 PM Rating: 5
Powered by Blogger.