Skip to main content

Posts

Showing posts from November, 2011

SharePoint Enable RMS Using Object Model

Step 1 Enable IRM on the farm SPWebService svc = SPFarm.Local.Services.GetValue (); SPIrmSettings irmSettings = svc.IrmSettings; irmSettings.IrmRMSEnabled = true; //set true or false based on the situation irmSettings.IrmRMSUseAD = true; irmSettings.IrmRMSCertServer = "certificate server here"; irmSettings.IrmChanges = irmSettings.IrmChanges + 1; svc.Update(); Step2 Set the IRM properties for a document library SPSite site = new SPSite("http:////"); SPList spList = site.OpenWeb().Lists["list_name"]; SPFolder folder = spList.RootFolder; spList.IrmEnabled = true; //corresponds to "Restrict permission to documents in this library on download" // BELOW SET=2, RESET=0 folder.Properties["vti_irm_IrmPrint" ] = 2; // Allow users to print documents folder.Properties["vti_irm_IrmVBA" ] = 2; // Allow users to access content programmatically folder.Properties["vti_irm_IrmOffline"...

Add an existing site collection Group to sub site with modified Roles

OBJECTIVE The site collection contains a group named “All Members” with “Contributor” privilege. I want to add this group programmatically to a sub site and modify its roles from “ Contributor ” to “ Read ” without modifying the original group. The following are the variables used in the code:        -            site: the SPSite object of the site collection being used -            web: the SPWeb object of the sub site you want to add the group to. SOLUTION: SPGroup  group = site.RootWeb.SiteGroups[ "All Members" ]; SPRoleAssignment  roleAssignment =  new   SPRoleAssignment (group); SPRoleDefinition  roleDefinition = site.RootWeb.RoleDefinitions[ "Read" ]; roleAssignment.RoleDefinitionBindings.Add(roleDefinition); if  (!web.HasUniqueRoleAssignments)       web.BreakRoleInheritance( true ); web...

Start User Profile Synchronization Service through Powershell cmd

Function ConvertTo-UnsecureString ([System.Security.SecureString]$string)    {    $unmanagedString = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUni code($string)     $unsecureString = [System.Runtime.InteropServices.Marshal]::PtrToStringUni ($unmanagedString)       [System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode ($unmanagedString)             return $unsecureString      } $syncMachine = Get-SPServer "sp2010dev" $profApp = Get-SPServiceApplication | where {$_.Name -eq "User Profile Service Application 1"} $account = Get-Credential "localdev\spfarm" if ($syncMachine.Address -eq $env:ComputerName) {     $syncSvc = Get-SPServiceInstance -Server $env:ComputerName | where {$_.TypeName -eq "User Profile Synchronization Service"}     $syncSvc.Status = [Microsoft.SharePoint.Administration.SPObjectStatus]::Pr...

Start User Profile Synchronization Service through Powershell cmd

Function ConvertTo-UnsecureString ([System.Security.SecureString]$string)    {    $unmanagedString = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUni code($string)     $unsecureString = [System.Runtime.InteropServices.Marshal]::PtrToStringUni ($unmanagedString)       [System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode ($unmanagedString)             return $unsecureString      } $syncMachine = Get-SPServer "sp2010dev" $profApp = Get-SPServiceApplication | where {$_.Name -eq "User Profile Service Application 1"} $account = Get-Credential "localdev\spfarm" if ($syncMachine.Address -eq $env:ComputerName) {     $syncSvc = Get-SPServiceInstance -Server $env:ComputerName | where {$_.TypeName -eq "User Profile Synchronization Service"}     $syncSvc.Status = [Microsoft.SharePoint.Administration.SPObjectStatus]::Pr...

Get All SubWebs using Client Object Model

  static string mainpath = "http://triad102:1001";         static void Main(string[] args)         {             getSubWebs(mainpath);             Console.Read();         }         public static  void  getSubWebs(string path)         {                       try             {                 ClientContext clientContext = new ClientContext( path );                 Web oWebsite = clientContext.Web;                 clientContext.Load(oWebsite, website => website.Webs, website => website.Title);                 clientContext.ExecuteQuery();     ...