Friday, April 27, 2012

PowerShell: Total number of documents in SharePoint Site and Sub-Site

Let's say you want to know total number of document's in your SharePoint app including sub-site. Output is an excel file. Change the column in the script if you need additional columns here.



function Get-DocInventory($siteUrl, $outFileNameWithPath) {


[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)

$spWebApp = $rootSite.WebApplication

foreach ($site in $spWebApp.Sites) {

foreach ($web in $site.AllWebs) {

foreach ($list in $web.Lists) {

if ($list.BaseType -ne "DocumentLibrary") {

continue}

if ($list.Hidden) {

continue}

foreach ($item in $list.Items) {

$data = @{

"Web Address" = $web.Url

"Doc Lib Name" = $list.Title

"File URL" = $item.Url

"File name" = $item.File.name

"Title" = $item.Title

"Created" = $item["Created"]

"Created By" = $item["Created By"]}

New-Object PSObject -Property $data}}

$web.Dispose();}

$site.Dispose()}

Write-Host "File written to " $outFileNameWithPath}


function Get-Docs()

{

$siteUrl = Read-Host "Enter Site URL"

$outFilePath = Read-Host "Enter output file path (without file name)"

$outFileNameWithPath = $outFilePath.ToString() + "\uploadedDocs.csv"

Get-DocInventory $siteUrl $outFileNameWithPath
Export-Csv -NoTypeInformation -Path $outFileNameWithPath
}

#Set-ExecutionPolicy RemoteSigned
Get-Docs
 
 

Wednesday, April 11, 2012

SharePoint Migration: Migrating a page having DataViewWebPart from SharePoint 2007 to SharePoint 2010

Migrating a page having Data View Web Part from one server to a different server


I got this issue while moving the lists with MetaLogix Migration Manager. It’s a very common issue I have seen people struggling with. Time to fix these issues increases if count of DVWP increases.

By default, SharePointDesigner binds the control to the list instance using the list instance GUID. To resolve this we need to replace the GUIDs by the list name.

The steps to do this are:

1) On the attributes of the DataFormWebPart element replace the attribute ListName="{GUID}" by ListName="LIST_NAME" where LIST_NAME is the name of the list that you are binding to.

2) Go through all of the DataFormParameter elements and replace: WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{GUID}"

With:

WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="LIST_NAME"


3) Go to the ParameterBindings element and replace

ParameterBinding Name="ListID" Location="None" DefaultValue="{GUID}"


With:

ParameterBinding Name="ListName" Location="None" DefaultValue="LIST_NAME"


This should give you a GUID free DVWP that can be placed on a page layout used by multiple sites on your site collection (as long as the name of the list is the same on all sites).

Cheers!!!

Tuesday, April 10, 2012

Knowledge Base: Let's understand SharePoint 2010 14 hive

Microsoft has replaced the "12 hive" structure that we had in SharePoint 2007 with "14 Hive" structure in 2010.




Some of the folders in 14 hive are :



Program Files\Common files\Microsoft Shared\Web Server Extensions\14 -

This directory is the installation directory for core SharePoint Server files.



Program Files\Common files\Microsoft Shared\Web Server Extensions\14\ADMISAPI -

This directory contains the soap services for Central Administration. If this directory is altered, remote site creation and other methods exposed in the service will not function correctly.



Program Files\Common files\Microsoft Shared\Web Server Extensions\14\CONFIG -

This directory contains files used to extend IIS Web sites with SharePoint Server. If this directory or its contents are altered, Web application provisioning will not function correctly.



Program Files\Common files\Microsoft Shared\Web Server Extensions\14\LOGS -

This directory contains setup and run-time tracing logs.



Other newly added folders are :



Program Files\Common files\Microsoft Shared\Web Server Extensions\Policy -





Program Files\Common files\Microsoft Shared\Web Server Extensions\UserCode -

This directory contains files used to support your sandboxed solutions.



Program Files\Common files\Microsoft Shared\Web Server Extensions\WebClients -

This directory contains files related to the new Client Object Model.



Program Files\Common files\Microsoft Shared\Web Server Extensions\WebServices -

This directory contains new wcf or .svc related files.



Note : You should rewrite and recompile any code that refers to files and resources in "12" Hive structure.For example, if you have redeployed all of your files into the "14" folder and emptied your "12" folder, any references to files under the "12" folder will not work.

Cheers!!!