Wednesday, December 21, 2011

How to check Site collection on Content DB or Content DB from Web Application in SharePoint 2010


There is Power shell command by which you can get the details of Site collection listed in a content db.

 

 

List of Site collection from Content DB Name

 

PS C:\Users\Administrator > Get-SPsite -ContentDatabase WSS_Content

 

Result of this command will be like

 

Url                                                   

---                                                   

http://<Server Name>                                  

http://<ServerName>/sites/SearchCenter    

 

 

List of content DB  from Site URL

 

PS C:\Users\Administrator > Get-SPContentDataBase  -WebApplication http://<Server Name>

 

Result of this command will be like

 

 

Id                                   : 6535eccc-0189-43d4-b022-5123e4ee8507

Name                             : WSS_Content

WebApplication               : SPWebApplication Name=SharePoint - 80

Server                           : ServerName

CurrentSiteCount            : 2


Monday, December 19, 2011

Deploy WSP through PowerShell script in SharePoint 2010

In SharePoint 2010, we have power shell commands to do most of share point functionality.

Here is simple script to Uninstall-remove- add-install for any WSP


<#
Name       : WSPDeployment.ps1
Created by : Rajesh Soni
Created on : 19th Dec 2011
Purpose    : Deployment Script for WSPs,Before executing change all the veriables name defined at the top of ps script
#>

Add-PSSnapin Microsoft.SharePoint.Powershell

$WSPPath ="C:\WSPs\"
$WSPName="abc.wsp"
$WSPNameWithPath=$WSPPath +''+$WSPName
$SiteURL ="http://<URL Site>/"


function WaitForJobToFinish([string]$SolutionFileName)
    $JobName = "*solution-deployment*$SolutionFileName*"
    $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
    if ($job -eq $null) 
    {
        Write-Host 'Timer job not found'
    }
    else
    {
        $JobFullName = $job.Name
        Write-Host -NoNewLine "Waiting to finish job $JobFullName"
        
        while ((Get-SPTimerJob $JobFullName) -ne $null) 
        {
            Write-Host -NoNewLine .
            Start-Sleep -Seconds 2
        }
        Write-Host  "Finished waiting for job.."
    }
}


Write-Host "Uninstall Solutions "

Uninstall-SPSolution –Identity $WSPName -confirm:$false -WebApplication $SiteURL  
WaitForJobToFinish  $WSPName

Write-Host "Remove Solutions "
Remove-SPSolution –Identity $WSPName -confirm:$false


Write-Host "Add Solutions "

Add-SPSolution $WSPNameWithPath

Write-Host "Install Solutions "
Install-SPSolution –Identity $WSPName -Force -GACDeployment  -WebApplication $SiteURL  
WaitForJobToFinish  $WSPName

Write-Host -Fore Green "Successfully deployed"


Write-Host -Fore Green "List of solutions at server"

Get-SPSolution 

Remove-PsSnapin Microsoft.SharePoint.PowerShell

Monday, June 20, 2011

StringBuilder clear method


String builder does not have a clear method to clear the contents of stringBuilder, but if we want to add a clear method in StringBuilder, use the following method in your utility class.

 

    public static void Clear(this StringBuilder stringBuilder)

    {

      stringBuilder.Length = 0;

      stringBuilder.Capacity = 16;

    }

 

Benefit of this method is if we use same stringbuilder variable with clear the existing contents.

Like

 

StringBuilder sb =new StringBuilder();

Sb.append("abc xyz");

 

// If you want to clear the content of sb then

sb.Clear();

 

This should be provided by Microsoft by default because if we re-init the string builder variable every time when we want to clear the content it will take lots of memory.

Thursday, June 16, 2011

Noice Words in Sharepoint Search

Noise words in Share Point Search are words that have no search value in SharePoint. By default, there are few words (like a, and, is, in, it, of, the, to) in the English language that are ignored. 
You can find the noise words files for all of the languages at C:\Program Files\Microsoft Office Servers\12.0\Data\Config. 

This is a txt file (for English noiseeng.txt) and you can edit it to include the common 'curse' or ‘Bad’ words to prevent them from showing up when user type them into search.

 



Thursday, May 26, 2011

StringBuilder clear method

String builder does not have a clear method, but if we want to add a clear method in stringbuilder use the following method in your utility class.


public static void Clear(this StringBuilder stringBuilder)
{
stringBuilder.Length = 0;
stringBuilder.Capacity = 16;
}

Benefit of this method is if we use same stringbuilder variable with clear the existing contents.