Saturday, 30 September 2017

SharePoint Custom Solution/WSP Memory Leak Solution

Though the only known solution is re-build these custom WSP’s using best practices, its important to develop a detailed report on each custom assemblies on GAC and provide a report to fix these issues. So idea is to build a powershell script to

1) Export all the WSP solutions

2) Extract the WSP’s

3) Run SPDispose check on each DLL

4) Identify the assembly is in “Debug” or release mode

5) Export the report to CSV

Following link for download SPDisposeCheck

http://download.microsoft.com/download/B/4/D/B4D279A0-E159-40BF-A5E8-F49ABDBE95C7/SPDisposeCheck.msi

Download this script here:
Get-SPDisposeReport.ps1

PowerShell:

</pre>

<pre>

#

#.SYNOPSIS

#Creates SP Dispose report on all WSP's

#

#.EXAMPLE

#.\Get-SPDisposeReport.ps1

#

 

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

 

#Variables

$wspdir = "D:\WSP\WSPReport1" #Location to export all WSP's

$exportdir = "$wspdir\Export-$((get-date).toString('yyyyMMdd'))\"

$CSVLocation = "$wspdir\SPDisposeResults.csv"

 

#create directory

[IO.Directory]::CreateDirectory($wspdir)

 

#Function to export all WSP's

function Export-AllWSPs

{

 Write-Host Exporting solutions to $wspdir

 foreach ($solution in Get-SPSolution)

 {

 $id = $Solution.SolutionID

 $title = $Solution.Name

 $filename = $Solution.SolutionFile.Name

 Write-Host "Exporting $title to ¦\$filename" -nonewline

 try {

 $solution.SolutionFile.SaveAs("$wspdir\$filename")

 Write-Host "– done" -foreground green

 }

 catch

 {

 Write-Host "– error : $_" -foreground red

 }

 }

 

}

 

#Function to extract all WSP Packages

function Extract-AllWSPs

{

 #Retrieve the wsp files in this folder and subfolders

 $s = [system.IO.SearchOption]::AllDirectories

 $fileEntries = [IO.Directory]::GetFiles($wspdir,"*.wsp",$s);

 foreach($fullFileName in $fileEntries)

 {

 $fileName = $(Get-Item $fullFileName).Name;

 $dirName = $fileName.Replace(".wsp","");

 $extractPath = $exportdir + $dirName;

 $dir = [IO.Directory]::CreateDirectory($extractPath)

 

 #uncab

 Write-Host "Export $fileName started" -ForegroundColor Red

 $destination = $extractPath

 C:\Windows\System32\extrac32.exe $fullFileName /e /Y /L $destination

 }

 

}

 

#Function to get Assembly details

function Get-AssemblyCustomProperty

 {

 param

 (

 $assembly,

 $TypeNameLike,

 $Property = $null

 )

 

 $value = $null

 foreach ($attribute in $assembly.GetCustomAttributes($false))

 {

 if ($attribute.GetType().ToString() -like "*$TypeNameLike*")

 {

 if ($Property -ne $null)

 {

 # Select-Object -ExpandProperty fails if property value is $null

 try {

 $value = $attribute | Select-Object -ExpandProperty $Property

 }

 catch {

 $value = $null

 }

 }

 else

 {

 $value = $attribute

 }

 break;

 }

 }

 

 $value

 }

 

#Function to report SP Dispose check results

Function Get-SPDisposeResults()

{

 

 #Pause for 5 secs to ensure extract is complete

 Start-Sleep -s 5

 $Dir = get-childitem $wspdir -recurse

 $List = $Dir | where {$_.extension -eq ".dll"}

 $List | ForEach-Object {

 

 [string]$report = & "C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe" $_.fullname

 #remove repetitive strings

 $report = $report -replace "Note: This tool may report errors which are not actually memory leaks, otherwise known as false positives. Further investigation should be done to identify and correct real errors. It is designed to assist developers in making sure their code adheres to best practices for memory allocation when using SharePoint APIs. Please see the following for more information: http://blogs.msdn.com/rogerla/ http://msdn2.microsoft.com/en-us/library/aa973248.aspx http://msdn2.microsoft.com/en-us/library/bb687949.aspx", ""

 $build = "RELEASE";

 try {

 $info = @{}

 $assembly = [Reflection.Assembly]::LoadFile($_.FullName)

 $attr = $assembly.GetCustomAttributes([Diagnostics.DebuggableAttribute], $false)

 $info.IsJITTrackingEnabled = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'System.Diagnostics.DebuggableAttribute' -Property 'IsJITTrackingEnabled'

 #$info.IsJITOptimizerDisabled = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'System.Diagnostics.DebuggableAttribute' -Property 'IsJITOptimizerDisabled'

 #$info.DebuggingFlags = Get-AssemblyCustomProperty -Assembly $assembly -TypeNameLike 'System.Diagnostics.DebuggableAttribute' -Property 'DebuggingFlags'

 #Write-Host $_.FullName: +" IsJITTrackingEnabled "+ $info.IsJITTrackingEnabled

 #Write-Host $_.FullName: +" IsJITOptimizerDisabled "+ $info.IsJITOptimizerDisabled

 #Write-Host $_.FullName: +" DebuggingFlags "+ $info.DebuggingFlags

 

 } catch {

 throw $_

 }

 

 Write-Host $report

 

 # Create a hash table with all the data

 $hash = @{

 "Assembly" = $_.name

 "Report" = $report

 "Debug Mode enabled" = $info.IsJITTrackingEnabled

 

 }

 # Convert the hash to an object and output to the pipeline

 New-Object PSObject -Property $hash

 }

}

 

#Function calls

Export-AllWSPs

Extract-AllWSPs

Get-SPDisposeResults | Export-Csv -NoTypeInformation -Path $CSVLocation


 

Thank you very much

          Fahadullah Karimi

         SharePoint Specialist


How to retrieve data from multiple lists in SharePointSharePoint Interview Questions and Answers

Thursday, 28 September 2017

How to retrieve data from multiple lists in SharePoint

 SPSiteDataQuery class is used to retrieve data from multiple lists.
It queries the data query that can be performed across multiple lists in multiple web sites in the same web site collection.
 Usually it is used in list aggregation, where list data from team sites or other subsites is collated and presented in a single interface.
- It aggregates the data from SharePoint lists only while ignoring data from external lists. It return a DataTable class which can be used to access the data.

It will only return results from one list type at a time.

SPSiteDataQuery query = new SPSiteDataQuery();
query .ViewFields = “<FieldRef Name=”Title”/>”;
query .Lists = “<Lists ServerTemplate=”101″/>”;
query .Webs = “<Webs Scope=”SiteCollection”/>”;
query .Query = “<Where>” +
“<Contains>” +
“<FieldRef Name=”Title”/>” +
“<Value Type=”Text”>Conditional Parameter </Value>” +
“</Contains>” +
“</Where>”;

SPSite site = new SPSite(http://applicationurl);

SPWeb web = site.OpenWeb();
DataTable dt = web.GetSiteData(query);

dt.Rows[0]["Title"]);



 

Thank you very much

          Fahadullah Karimi

         SharePoint Specialist


SharePoint List Server Template IDsSharePoint Custom Solution/WSP Memory Leak Solution

SharePoint List Server Template IDs

Template IDs
 Template Type
 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 Decisions list 
207
Meeting Objectives list 
210
Meeting text box 
211
Meeting Things To Bring list 
212
Meeting Workspace Pages list 
300
Portal Sites list 
301
Blog Posts list 
302
Blog Comments list 
303
Blog Categories list 
402
Facility
403
Whereabouts 
404
CallTrack 
405
Circulation 
420
Timecard 
421
Holidays
499
IMEDic 
600
ExternalList 
700
MySiteDocumentLibrary 
850
Page Library 
1100
Issue tracking 
1200
Administrator tasks list 
1220
HealthRules 

1221

HealthReports 
1230
DeveloperSiteDraftApps 

2002

Personal document library 
2003
Private document library



Thank you very much

          Fahadullah Karimi

         SharePoint Specialist


Difference between the Master page and page layout in SharePointHow to retrieve data from multiple lists in SharePoint