Friday, December 12, 2014

Copy List Item Programmatically


public void CopyItem(SPListItem srcItem, SPListItem destItem) { foreach (SPField field in srcItem.Fields) { if (!field.ReadOnlyField && field.InternalName != "Attachments") { destItem[field.InternalName] = srcItem[field.InternalName]; } } foreach (string attachmentName in srcItem.Attachments) { SPFile file = srcItem.ParentList.ParentWeb.GetFile(srcItem.Attachments.UrlPrefix + attachmentName); byte[] data = file.OpenBinary(); destItem.Attachments.Add(attachmentName, data); } destItem.Update(); }

Wednesday, December 10, 2014

Thursday, December 4, 2014

Export ContentDataBase Name in csv file

<# Created by : Gaurav Goyal
   Purpose : To Export Content Database Name in csv file.
   Comments : Run With Admin Privileges \ Read operation.
#>

$csv="./CSV.csv"
$i=1;
SC $csv "ID,DBName,WebApplicationName,CurrentSiteCount"
write-host "`nGetting WebApplication Names`n";
$WebApps = Get-SPWebApplication 
foreach($WebAppUrl in $WebApps)
{
write-host "$i) Getting ContentDataBase name of WebApp" $WebAppUrl.Url "`n" ;$i++;
$toCSV=Get-SPContentDatabase -site $WebAppUrl.Url;
AC $csv "$($toCSV.Id),$($toCSV.Name),$($toCSV.WebApplication),$($toCSV.CurrentSiteCount)"
}
write-host "Exporting List of All DB.....`n"
Get-SPDatabase | epcsv ".\AllDataBaseList.csv"