Friday, August 5, 2016

Extending Sharepoint WebApplication

What is extending sharepoint webapplicaiton?

Let's take an example to understand this concept.

Assume we have two sharepoint site but the content of both sites are same. Here the question raises do we need to create the same content for both the sites or is there any possibility that sharepoint infrastructure provide us some mechanism to handle this in elegant way.

so here comes the concept of extending the sharepoint web  applicaion:

Expose the same content to two different set of users with different URL's and with different authentication will use  the concept of extending  sharepoint  web applicaiton.

Each  Web  app will assign  to corresponding IIS  web site and when it get extended it will create another web applicaiton and inturn it create new IIS web site as well.
The extended web app will use the same content DB as with  the main web app(here we can call it as parent web applicaiton), since it will create its own  IIS web site it will be having its own Web.config  file.

This concept will be handy when parent site use windows  authentication and extended site uses form based  authentication

Note: By default extended web applicaiton uses the  same authentication as with the parent  site, but we can change  it as per the  requirement.

Saturday, July 2, 2016

Uninstall DLL from Gac using Powershell

In some cases we might face issue while deleting the dll from GAC( usually it will say its in use by some process) and it will always annoying, to over come this here is small powershell script which will be handy.

Set-location "Folder path of the DLL"          
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")          
$publish = New-Object System.EnterpriseServices.Internal.Publish          
$publish.GacRemove("FolderPath\DLL.dll")          
iisreset


Thursday, December 17, 2015

When do we need sharepoint full crawl?

Most of the developers have encountered this question, when exactly do we need to run the sharepoint full crawl? Why does incremental crawl is not enough.

Here are the following scenarios where full crawl is mandatory.

a) Search  service application created  in the farm and configured with content source(Its obvious)
b) New content source added/created.
c) Adding new  managed property/ updating the existing managed property.
d) After CRUD operation of Crawl Rules
d) If  search index  throwing errors
e) The  credentials of  user account that is assigned to the default content access account have changed
f)  Sharepoint Service pack installed

Atleast for  the above scenarios its  mandatory to run  the full crawl else  search does not return the required results :(




Monday, October 19, 2015

How to create and import thesaurus in SharePoint Server

Before deep dive into how to create and import first we will discuss about thesaurus

What is Thesaurus?

Its same as synonym or as per google :) "a book that lists words in groups of synonyms and related concepts"

Before jump into the details, we will make clear that it will be used in sharepoint search.

Why it is  important in sharepoint world?

As explained above this is used in sharepoint search, so many people can search for the same data using different key world.

ex: If user wants to search for Laptop, then the user can try with different keywords like shown below :

Lap top
Laptop
Laptops
Lappy
Lap-top

In all of the above cases its referring to Laptop only, but how our sharepoint will understand these keys will be explained in the post

The situation becomes even difficult when people use acronyms :(

ex: HD TV
Hi Definition TV etc

In all of the above cases, search doesn't return any of the record even when user is referring to the same type/record

How to overcome this issue?

In Sharepoint 2013 we can easily create and upload the thesaurus(csv format) that contains synonyms for search phrases and acronym as well.

How to create it?

First we need to identify which are thesaurus we need to use in the system like as explained for Laptop example

1) Then open notepad(We can use CSV also)

2)  In the notepad enter the columns name like Key,Synonym,Language
Note: It should be at the top and there is no  space between 3 words and it should be separated  by comma.
ex:Key,Synonym,Language









3) In the text editor add new line and enter a term or a phrase, a synonym for that term or phrase and a two letter language code. Use commas to separate the phrases, for example Lap-top,Laptop,en

Note: Here Language is optional 

Repeat the same steps for entering multiple term as like below

Lap top,Laptop,en
Laptop,Laptop,en
Laptops,Laptop,en
Lappy,Laptop,en
Lap-top,Laptop,en
Lap Top,Laptop,en
Lap Tops,Laptop,en

Save the file as .csv with UTF-8 encoding.

Now our thesaurus are ready for importing into Sharepoint.









How to import into sharepoint environment?

1) Open a SharePoint 2013 Management Shell with Admin account(Search service application administrator)

2) In the command prompt  enter  the  following command

$searchApp = Get-SPEnterpriseSearchServiceApplication 
Import-SPEnterpriseSearchThesaurus -SearchApplication $searchApp -Filename \\sharepoint2013\\D$\Searchthesaurus\Thesaurus.csv

Here file path is given in the UNC format. This commandlet expects the file path in this format.






Now our thesaurus are part of search, even if the user search for any of the term search will return the proper results

Things to consider:

When we import  the thesaurus  existing  thesaurus will be overwritten.

There is no export functionality to take backup of the  existing thesaurus
(Its good to maintain the thesaurus files in external system where we can update the new thesaurus)

After  importing  thesaurus it will reflect  immediately, there is no delay in reflection

Its always better to update the existing copy of the thesaurus file so that all old entries will be available.

Issue might encounter  and steps to fix the issue

1) If we run the commandlet without admin access it might throw exception

2) Search needs to be properly configured

3) Make sure whatever term you are mapping its coming in the search result or not before running the scripts
ex: Laptop word  is coming or not please verify before running this.

4) After running the commandlet if you are seeing the below error in ULS then we need to restart Search and Timer service
Failed to start the flow: Microsoft.ThesaurusDeployment. Exception: System.ServiceModel.FaultException: Cannot start flow. The admin service is unavailable.

5) Make sure Primary host controller is enabled in the front end server where this scripts is running












Friday, May 30, 2014

Check Sharepoint page is in edit mode or not

Today I came across one of the scenario where i need to check page is in edit mode or not.
Scenario: We have sharepoint custom webpart which needs to be cached. Problem here was if the user update the any of the webpart property it was not reflecting automatically(another way we can achieve this was using webpart tool property)

Because, in the create child control method we are checking whether the control is cached or not, since the webpart was available in the cache this was not rebuilding the control.

So solution for this problem is if page is in edit mode then rebuild the webpart else check if the webpart is available in the cache if it is available then get it from there else rebuild the control.

//The below code will work if we are using pages which are associated to page layout
if(Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit)
{
         //Page is in edit mode
         BuildTheWebpart();
}
else
{
         //Page is in display mode 
         if(WebpartIsAvailableInCache())
         {
              //Get the webpart from cache and render it
         }
         else
         {
              BuildTheWebpart();
         }
}


What about if it is simple webpart page?

WebPartManager wpManager = this.WebPartManager;
if (wpManager.DisplayMode == WebPartManager.EditDisplayMode)
{
//This indicated page is in edit mode
BuildTheWebPart();
}
else
{
  //Page is in display mode
         if(WebpartIsAvailableInCache())
         {
              //Get the webpart from cache and render it
         }
         else
         {
              BuildTheWebpart();
         }
}

But none of the above code didn't solve my problem. The page was provisioned through feature and its not associated to any page layout it just provisioned in the page library.

The simplest fix i found out is check page is checked out or not


Usually for all sharepoint sites this will be activated by administrator so we can use this to check page is in edit mode or not 


if(Microsoft.SharePoint.SPContext.Current.FileLevel = SPFileLevel.CheckOut)
{
     //Edit mode
     Build the control
}
else
{
    //page is checked in so user is not updating any of the webpart property
}



Hopefully if any one face the issue like me can use this check to determine page is in edit or not.

Thursday, May 15, 2014

Connecting Social Media in Sharepoint

I have created Social webpart which will interact with Facebook and twitter. This has been displayed in tabs, when user click on Facebook its related post will display if the user clicks on Twitter then all the tweets will display. I have uploaded the source code/project in codeplex, please provide the feed back/comments.

https://sharepointsocialcontrol.codeplex.com/

Tuesday, May 13, 2014

How to register Javascript & CSS file in custom webpart

In this post will explain about how we can register CSS and Javascript files in the webpart code.

What are the advantages of registering CSS and JS file through webpart?

Lets assume if we register CSS and JS file in masterpage every time this files will be loaded irrespective of whether webpart rendered in the page or not. This will be increase response time for the page. To overcome this we can register CSS and JS file in the webpart.

How we can achieve this?

If we are using custom webpart then in the on pre render method we can use below snippet of code to register the CSS & JS file.


protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            try
            {
                //This is the sharepoint layout mapped folder which contain jQuery and javascript file
                ScriptLink.Register(this.Page, "/_layouts/Scripts/jquery-1.9.1.min.js", false);
                ScriptLink.Register(this.Page, "/_layouts/Scripts/customJS.js", false);

                CssRegistration wpCss = new CssRegistration();
                //Location of the CSS file path
                wpCss.Name = "FilePath";
                //Lets assume we need to load the webpart CSS file after the main CSS file or it may                   be after core.css file
                wpCss.After = "MainFileName";
                this.Controls.Add(wpCss);
            }
            catch (Exception ex)
            {
            }
        }