Wednesday, August 3, 2011

Update folder name of List or Library programmatically in sharepoint 2010

Sharepoint Document Library
==========================
if (oWeb.Lists.TryGetList("Working Documents") != null)
{
SPList listWorkingDocs = oWeb.Lists["Working Documents"];
folderUrl = oWeb.Url + "/" + listWorkingDocs.Title + "/" + listPreviousTitle;
SPFolder folder = oWeb.GetFolder(folderUrl); //listWorkingDocs.RootFolder.SubFolders[listPreviousTitle];
if (folder.Exists)
{
SPListItem item = folder.Item;
item["BaseName"] = "newfoldername";
item.SystemUpdate(false);
}

}

Sharepoint List
===================SPList listTasks = oWeb.Lists["Tasks"];
folderUrl = oWeb.Url + "/Lists/" + listTasks.Title + "/" + foldername;

SPFolder folder = oWeb.GetFolder(folderUrl);
if (folder.Exists)
{
  SPListItem item = folder.Item;
  item["FileLeafRef"] = "newfoldername";
 item.SystemUpdate(false);
}

Tuesday, August 2, 2011

Update content type filed in the shareponit 2010 list using powershell script

$siteUrl = "http://servername/sites/P127036/"
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") > $null
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$RootWeb = $site.RootWeb
$EventsList ="MyList"
  if ($EventsList -ne $null)
   {
        $MissionContentType = $EventsList.ContentTypes["Mission"]
  $field = $MissionContentType.FieldLinks["Category"]  # here u shuld not take Field
  $field.Hidden = $true
  $MissionContentType.Update();
  $EventsList.Update()
}
# Dispose the site object
if ($site) {$site.Dispose()}
if ($RootWeb){ $RootWeb.Dispose()}

upgrade sharepoint 2010 wsp using powershell script


# Example: "D:\SiteBackUp\" - Remember the backward slash '\' at the end of the path.
$SharedLocation = "D:\Projects\DeployFiles\New Folder\"
# Example: "http://siteurl/"
$Weburl = "servername"
# Example: 80
$WebPort = "33980"
# **********************************************************************************************************************************
# Check if folder exists
      if (Test-Path $SharedLocation)
      {
            # Get all the WSP files from the solution folder
            $list = Get-ChildItem ($SharedLocation) | where {$_.extension -eq ".wsp"}
            # Loop through each wsp file in the solutions folder
            foreach($wspfile in $list)
            {
                  # Retrieve the solution package already added
                  $CheckPackage = Get-SPSolution -identity $wspfile.Name
                  write-host "Deploying Solution: " $wspfile.Name
                 
                  if ($CheckPackage
                  {
                        if ($CheckPackage.ContainsWebapplicationResource)
                        {
                              if ($CheckPackage.ContainsGlobalAssembly)
                              {
                                  Update-SPSolution –Identity $CheckPackage –LiteralPath ($SharedLocation + $wspfile.Name) -GacDeployment
                              }
                              else    
                              {
                                     Update-SPSolution –Identity $CheckPackage –LiteralPath ($SharedLocation + $wspfile.Name)
                              }   
                        }  
                         else
                        {
                               if ($CheckPackage.ContainsGlobalAssembly)
                              {
                               Update-SPSolution –Identity $CheckPackage –LiteralPath ($SharedLocation + $wspfile.Name) -GacDeployment
                              }
                               else
                              {
                              Update-SPSolution –Identity $CheckPackage –LiteralPath ($SharedLocation + $wspfile.Name)
                              }
                        }
                  }
            }
      write-host "Solution pack upgrades completed successfully...!"
      }
      else
      {
      " No shared/local folder found ! Please check the shared location path !!"
      }

Update Title Sharepoint 2010 List using Powershell 2010

$siteUrl = "http://servername/sites/P127036/"
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") > $null
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$RootWeb = $site.RootWeb
$lookForList ="Bookmarks"
 $BookmarksList= $RootWeb.Lists[$lookForList]
   if ($BookmarksList -ne $null)
    {
   $BookmarksList.Title = "Links"
   $BookmarksList.Update()
 }

# Dispose the site object
if ($site) {$site.Dispose()}
if ($RootWeb){ $RootWeb.Dispose()}

Rename Content type name in the list using Powershell

$siteUrl = "http://servername/sites/P127036/"
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") > $null
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$RootWeb = $site.RootWeb

$lookForList ="Tasks"
$TaskList= $RootWeb.Lists[$lookForList]
   
    if ($TaskList -ne $null)
    {
        $TaskContentType = $TaskList.ContentTypes["Custom Tasks"]

  if ($TaskContentType -ne $null)
  {
     $TaskContentType.Name = "Tasks"
     $TaskContentType.Update()
  }
  
}

# Dispose the site object if ($site) {$site.Dispose()}if ($RootWeb){ $RootWeb.Dispose()}

Update Workspace URL using Powershell

Below script for it loops through all of your sites in the server

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
$WebAppUrl = "servername"
$site = new-object Microsoft.SharePoint.SPSite($WebAppUrl)
$web = $site.OpenWeb()
$list = $web.Lists["Projects List"]
$query = new-object Microsoft.SharePoint.SPQuery
$query.Query = "<Where><Eq><FieldRef Name='Status' /><Value Type='Choice'>Success</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>"
#$query.RowLimit = 2
[xml]$viewfields = "<ViewFields><FieldRef  Name='Project_x0020_ID' /><FieldRef Name='Title' /></ViewFields>"
$result = $list.GetItems($query)
#Write-Host $result.count
foreach ($resultItem in $result)
{
  $siteURL = $resultItem["SiteURL"]
        $oRootsite = new-object Microsoft.SharePoint.SPSite($siteURL)
        $RootWeb = $oRootsite.OpenWeb()        
  $lookForList ="Events"
  $EventsList= $RootWeb.Lists[$lookForList]
   
   if ($EventsList -ne $null)
     {

    $queryEvents = new-object Microsoft.SharePoint.SPQuery
   $queryEvents.Query ="<Where><Eq><FieldRef Name='WorkspaceLink' /><Value Type='CrossProjectLink'>1</Value></Eq></Where>"
   #[xml]$viewfields = "<ViewFields><FieldRef  Name='Project_x0020_ID' /><FieldRef Name='Title' /></ViewFields>"
   $Queryresult = $EventsList.GetItems($queryEvents)
   Write-Host $siteURL  + ":" + $Queryresult.Count
   foreach ($eventListItem in $Queryresult)
   {
    
    if($eventListItem["WorkspaceLink"]  -eq $true)
    {  
    $eventListItem["Workspace"]= $null
    $eventListItem.SystemUpdate($false)
    Write-Host $eventListItem["Title"]  "---"  $eventListItem["Workspace"]
    }
   }
  }

  # Rollout OPS Project Stages and Update document edit form
  # Enable-SPFeature –Identity "be307273-d9de-4f16-84d2-52b5e1467ff0" –url $siteURL


}

for single site

$siteUrl = "http://servername/sites/P127036/"
[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") > $null
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$RootWeb = $site.RootWeb
$lookForList ="Events"
$EventsList= $RootWeb.Lists[$lookForList]
  if ($EventsList -ne $null)
    {
  $query = new-object Microsoft.SharePoint.SPQuery
 $query.Query ="<OrderBy><FieldRef Name='Title' /></OrderBy>"
 #[xml]$viewfields = "<ViewFields><FieldRef  Name='Project_x0020_ID' /><FieldRef Name='Title' /></ViewFields>"
 $result = $EventsList.GetItems($query)
 Write-Host $result.count
 foreach ($resultItem in $result)
 {
  if($resultItem["WorkspaceLink"]  -ne $false)
  {
  Write-Host $resultItem["Title"]  "---"  $resultItem["Workspace"]
  $resultItem["Workspace"]= $null
  $resultItem.SystemUpdate()
  Write-Host  "After updated:"  $resultItem["Workspace"]
  }
 }
 
}

create custom field Person/ Group in Sharepoint 2010

<Field SourceID="http://schemas.microsoft.com/sharepoint/v3"
ID="{D8B1733D-AEC2-4bb0-B8FB-FB8DE59B740}"
Name="OPS_AttendeeName"
StaticName="AttendeeName"
DisplayName="Name"
Group="Site Columns"
Type="UserMulti"
Mult="TRUE"
Hidden="FALSE"
ReadOnly="FALSE"
Required="FALSE"
ShowInViewForms="TRUE"
PITarget=""
PrimaryPITarget=""
PIAttribute=""
PrimaryPIAttribute=""
List="UserInfo"
ShowField="ImnName"
UserSelectionMode="PeopleAndGroups"
UserSelectionScope="0"
Node=""/>

Followers