Wednesday, 27 May 2015

Reserved querystring parameter in Sharepoint

Below querystring parameters are reserved in SharePoint and using them may give unpredictable results.

  • FeatureId
  • ListTemplate
  • List
  • ID
  • VersionNo
  • ContentTypeId
  • RootFolder
  • View
  • FolderCTID
  • Mode
  • Type
  • PageVersion
  • IsDlg
  • Title
  • _V3List_

To ensure that the creation of the SPContext object does not fail your application should ensure that your query string parameters are different from those listed above.


Tuesday, 26 May 2015

How to exclude or skip part of page content from SharePoint search crawler

To do this we have to use the "noindex" class, like this,

<div class="noindex"> footer </div>

This will be helpful if you want to avoid footer to get crawled in search. Because of the fact that the footer is part of the master page the crawler may index every single page that inherits from the master page. This will cause misleading and wrong search results for the visitors of the site.

Monday, 25 May 2015

How to change default tile size in SharePoint 2013

Using a CSS can be approach to achieve this.

Add the following CSS inside the content editor webpart or add it to your custom css

<style type="text/css">
                height: 100px;

                height: 110px !important;
                width: 110px !important;

  ,, > a > div > span {
                height: 100px !important;
                width: 100px !important;

   > a > div > img {
                max-width: 100%;
                width: 100% !important;

                height: 100px;
                padding: 0;

                font-size: 11px;
                line-height: 16px;

  ,, {
                padding: 3px;

                background: none repeat scroll 0 0 #002E4F;
                font-size: 12px;
                line-height: 16px;
                min-height: 36px;
                min-width: 97px;
                padding-left: 3px;
                position: absolute;
                top: -36px;

                font-size: 11px;
                line-height: 14px;
                padding: 3px;


Hope this helps..!!!

How to find all document of particular content type

We can use below powershell to find documents of certain content type:

 $site = Get-SPSite("your-site-url");  
 foreach ($web in $site.AllWebs) {  
   $ctype = $web.ContentTypes["Your Content Type"]  
   $usages = [Microsoft.Sharepoint.SPContentTypeUsage]::GetUsages($ctype)  
   foreach ($usage in $usages) {  
    Write-Host $usage.Url  

To find it using code you can below lines of code

 using (SPSite siteCollection = new SPSite("http://localhost"))  
       using (SPWeb webSite = siteCollection.OpenWeb())  
         // Get the content type.  
         SPContentType obsolete = webSite.ContentTypes["Test"]; 
         // We have a content type.  
         if (obsolete != null)   
          IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(obsolete);  
          // It is in use.  
          if (usages.Count > 0)   
            Console.WriteLine("The content type is in use in the following locations:");  
            foreach (SPContentTypeUsage usage in usages)  
          Console.WriteLine("The content type does not exist in this site collection.");  
      Console.Write("\nPress ENTER to continue...");  

Hope this helps.!!!!!!!

Change linked to item with edit menu to different column

Normally a SharePoint list links to an item using the “Title” field. But in some cases you want to hide Title Column and and add linked to item link to another column.

Now to link the Item to a specific column/field, you need to open the list in SharePoint designer and look for the <viewfields> tags.
And then add LinkToItem="TRUE" to whichever column you want the link.

   <FieldRef Name="field1"/><br/>  
   <FieldRef Name="field2"/><br/>  
   <FieldRef Name="field3" LinkToItem="TRUE"/><br/>  
   <FieldRef Name="field4"/><br/>  
   <FieldRef Name="field5"/><br/>  

Save and you are done.!!!!!!

Wednesday, 6 May 2015

Upload file into SharePoint doument library with metadata using PowerShell

In this post we will see how to upload the file into the document library and insert/update the metadata columns. I am having 1 people picker data types/user group columns and 1 single line of text columns.

Below is the PowerShell to upload documents in PowerShell and update the metadata:

        if((Get-PSSnapin | Where {$_.Name -
        eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
            Add-PSSnapin Microsoft.SharePoint.PowerShell;

           #Site Collection where you want to upload files
          $siteCollUrl = "YourSiteURL"
          #Document Library where you want to upload files
         $libraryName = "DocLibName"
         #Physical/Network location of files
          $reportFilesLocation  = "D:\FileUpload"

        $spSourceWeb = Get-SPWeb $siteCollUrl;
        $spSourceList = $spSourceWeb.Lists[$libraryName];

            if($spSourceList -eq $null)
           Write-Host "The Library $libraryName could not be found."

   $files = ([System.IO.DirectoryInfo] (Get-Item 
  foreach($file in $files)
    #Open file
   $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()

   #Add file
   $folder =  $spSourceWeb.getfolder($libraryName)

   Write-Host "Copying file $file to $libraryName..."
   $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name,   
   [System.IO.Stream]$fileStream, $true)

$item = $spFile.Item;
$item["TextOrChoiceColumnInternalName"] = "New Value"
$spUser = Get-SPUser -Identity "domain\username" -Web $spSourceWeb;
$item["UserFieldInternalName"] = $spUser;
#Use SystemUpdate($false) if you don't want to increase the version of the item..

   #Close file stream
Write-Host "Files have been uploaded to $libraryName."

Using this PowerShell script you can upload documents with metadata.

To check in a file use:
$spFile.CheckIn("Checked In By Administrator")

To publish a file:
$spFile.Publish("Automatically published by Powershell")

To approve a file:
$spFile.Approve("Automatically approved by by Powershell");

Hope this helps!!!

How to access SharePoint server “Outgoing E-Mail Settings” from code?

Outgoing email setting are configured in central administration at path:

Central Admin -> System Settings -> Configure outgoing e-mail settings

Below is the code to access outgoing e-mail settings using object model:

//Get the site ID
Guid siteID = SPContext.Current.Site.ID;
protected string GetSMTPHostName()
    using (SPSite site = new SPSite(siteID))
      //Get the SMTP host name from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailServiceInstance.Parent.Name;
protected string GetFromEmailID()
    using (SPSite site = new SPSite(siteID))
      //Get the “from email address” from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailSenderAddress;


Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Tuesday, 5 May 2015

How to start the workflow for an item using PowerShell / C#

In this article we will be seeing how to start a workflow for an item using c# and powershell

Start a workflow using c#

class Program    {
        static void Main(string[] args)
            using (SPSite site = new SPSite("YourSiteURL"))
                using (SPWeb web = site.RootWeb)
                    SPList list = web.Lists["Test"]; 
                    SPListItem item=list.Items[0];
                    SPWorkflowManager manager = site.WorkflowManager;
                    SPWorkflowAssociation association = list.WorkflowAssociations[0];
                    string data = association.AssociationData;
                    SPWorkflow wf = manager.StartWorkflow(item, association, data, true);

Start a workflow using powershell:

$site=Get-Spsite $siteURL

Hope this helps!!!!

How to get document library size using PowerShell?

Below is the PowerShell script which will show the size of Particular library:

    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=,             Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=,   Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

    $siteURL = "YourSiteURL" 
    $site = new-object Microsoft.SharePoint.SPSite($siteURL)

    foreach ($web in $site.AllWebs)
     foreach ($list in $web.Lists)

            if($list.BaseType -eq "DocumentLibrary")   

if($list.Title -eq "YourDocumentLibraryTitle")
        $listSize = 0
       foreach ($item in $list.items) 
              $listSize += ($item.file).length
         "Web: "+$web.Title+", Library Name: "+$list.Title+", Size: "+[Math]::Round(($listSize/1KB),2)+"KB"     

Hope this helps!!!!

Related Posts Plugin for WordPress, Blogger...