Thursday 31 October 2013

SPDisposeCheck With Visual Studio

SPDisposeCheck is a great tool to check memory leakage for SharePoint objects. We must check for SharePoint objects should be disposed to improve performance. While using SharePoint server object model we generally use SPSite, SPWeb in our code  which should be disposed to avoid memory leaks.SPDisposeCheck helps to find such memory leaks caused due to SharePoint objects.   
1.    Download SPDisposeCheck
2.       Install SPDisposeCheck and copy the path of installation. In my case it was:
C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\

3.       Add SPDisposeCheck to Visual Studio

A.      Goto  Tools > External Tool..
 



B.      Click Add and provide title for tool. Paste the installation path to Command and do the changes mentioned in below picture.
C.      Check if SPDisposeCheck is added or not
  


4.       Click On SharePoint SPDisposeCheck .

5.       Here you can select whether problem should be treated as warnings or error. For both the option solution can be build and deployed.


6.       Test the solution by deploying or you can just build the solution to get SPDisposeCheck output at Output window of Visual Studio.

Saturday 21 September 2013

Migrating Content DataBase from one server to another server in SharePoint 2010


Here are the simple steps to migrate a content database from one SharePoint 2010 server to another SharePoint 2010 server. Basically this task is divided into two parts:
Part-1: Taking Backup of your content DB using SQL Server Management Studio
Part-2: Restoring Backup file of your content DB to another server using SQL Server Management Studio

Part-1: Taking Backup of your content DB using SQL Server Management Studio
[Server 1]
1. Open SQL Server Management Studio as administrator using your credentials. You can see a list of databases available on your server, select the database of which you want to take backup.


2. Right click to your content DB then go to
Tasks > Back Up…

Below screen will appear.

Click OK.

Click Ok again. Backup is done, copy the backup file (.bak) and move it to the server where you to restore.  
Part-2: Restoring Backup file of content DB to new server using SQL Server Management Studio
[Server 2]
1. Open SQL Server Management Studio as administrator using your credentials. Right click Databases, and then go to Restore Database

2. Select the file using “From device” option and click OK.

On successfully completion of restore a pop-up message will appear with the message that “Restore of content database ContentDBName Completed successfully”.
Now your content database is available on another server. And now we are going to replace the newly added content database with old one.
3. Go to
Central Administration > Manage Content Databases
Select the web application

4. Click on content database and check “Remove content database” and click ok. This will remove the existing content database.

5. Click “Add a content database” and enter newly restored content database name.
 And click ok.

Content database is now added to desired web-application.
6. Go to the SharePoint site to see changes.
  
Below are the two screen shots from two different server having same content database.

Server 1 (old ) :


Server 2(new):

Thursday 5 September 2013

Creating Custom HTML Master Page In SharePoint 2013

SharePoint 2013 came up with new trend of creating master pages for SharePoint which is HTML Master Page . Now creating master pages becomes more easy .All you have to do is create your custom HTML markups and with the help of SharePoint 2013 Design Manager ,you can easily convert your normal HTML file to a SharePoint 2013 master page.Here are the steps to create SharePoint 2013 Custom HTML Master page .


1.Prepare your HTML layout ,you can use Dreamweaver or other HTML editor tool.I have create below HTML layout using Visual Studio . 

<html >
<head><title>SPCircle</title><!-- Reference to css --><link rel="Stylesheet" href="/MyStyle/MyMasterStyle.css" /></head><body class="Mybody"><div id="OuterContainer"><div id="MainContainer"><div id="MyHeader"><!-- Header Part --><div id="MyHeaderLeft"><p id="SPC">SPCircle</p></div><div id="MyHeaderRight"><div id="MySearchBox"></div></div></div><div id="MyMenuContainer"><!-- Menu PArt --><div id="MyMenu"></div></div> <div id="ContentContainer" ><!-- Main content of the page will go here --></div><div id="MyFooter"><!-- Footer Part -->
<div id="leftFooter" ></div><div id="rightFooter"></div></div> 
 
</div></
div></body></
html>        As you can see its a pure HTML no other tags are used .Once you completed with your HTML layout ,next step is to put all your files (HTML file, css ,script files, images ) to SharePoint library.

2.Go to

Site Settings >Master page and page layouts > Upload Document

Browse and upload you HTML File to this library,select HTML Master Page from dropdown list .



3.Fill the required description and check  complatible UI for 4 and 15 and press Ok.





4.Publish the uploaded file.



5.Upload your design files (css, javascript ,jQuery files and images) to the path mentioned in you HTML markups or css files .

6.Go to Design Manager


7.Click Edit Master Pages

8.Click on convert an HTML file to SharePoint Master Page


9.Select HTML Master Pages to convert


10.Click ok .Your selected file will gets converted to master page .

 11.Click on the file , you will be redirected to preview page.



So, your HTML is converted to Master Page .Now next job is put SharePoint components like ,top navigation , vertical navigation ,search box to your master page .

12.Click on Snippets Gallery ,a new window will gets opened .Now if u want to add top-navigation  click on the Top-Navigation ,a html snippet will gets generated .Copy the html snippet and paste it on HTML file at appropiate palce.


   For editing and placing HTML snippet, open your html file into SharePoint designer to make this job more easy.Paste the snippet into HTML file and save the file .Refresh the preview page to see changes.Similarly you can add other snippets and snippet gallery.

Note:Move the highlighted(yellow) area to the palce where you want to put main containt of the page.  




13. Once you done , goto master page gallery to approve and publish your newly created master page ,to make it availaible and start using it .

Tuesday 3 September 2013

CAML Query not working in SharePoint 2010

CAML query is really very helpful while working with SharePoint Server Object Model to query data from SharePoint list and libraries.But while working with Server Object Model I was facing one issue ,that my query was not working properly, as i was not getting expected result.I also debug the code and their was no error while debugging in query.Below is the SPQuery which was not working.


SPQuery getSubHeaderQuery = new SPQuery();

getSubHeaderQuery.Query = "<Query><Where> <Eq> <FieldRef Name='MainHeader'/> <ValueType='Lookup'>" + MainHeader + "</Value> </Eq></Where></Query>";




Solution:

After spending some time and struggling with above query , i got soloution and finally my query starts working.Solution is very simple ,just remove the <Query> </Query> tag from the query string  and it will work fine .


SPQuery getSubHeaderQuery = new SPQuery();
getSubHeaderQuery.Query = "<Where> <Eq> <FieldRef Name='MainHeader'/> <Value Type='Lookup'>" + MainHeader + "</Value> </Eq></Where>";

 





Friday 30 August 2013

Adding custom menu Item in Welcome Menu of SharePoint 2010


In this post i m going to add my custom menu in SharePoint 2010 Welcome Menu block .You can see default options which i have in my site's welcome menu block.  



Steps to add new menu item in welcome menu :


1.Open Visual Studio as administrator.

2.Create a new Empty SharePoint project.



3.Select for farm solution deployment



4.Add new feature to solution








5.Click on add new item




6.Select empty Element and rename it.



7.Write the below code in Element.xml file

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
   
  Id="myCustomAction"
 
  GroupId="PersonalActions"
 
  Location="Microsoft.SharePoint.StandardMenu"
 
  Sequence="1000"
 
  ImageUrl="/images/changepassword.png"
 
  Title="Change Password"
   
  Description="Change your password from here">
   
  <UrlAction Url="/Pages/changepassword.aspx"/>
    

  </CustomAction>
 
</Elements>


9.Deploy the solution



10.Refresh page and click on welcome menu , you can see your newly added menu item








Monday 19 August 2013

Enabling Developer Dashboard using Powershell in sharepoint 2010

 


Developer Dashboard is a new feature in SharePoint 2010 , to take a look and understand the page performance . Now developer can see various performance related information and can optimize page performance accordingly .This feature was not availaible in early version of SharePoint .


1.Open Sharepoint 2010 Management Shell as administrator .


2.Basically their are 3 modes which Sharepoint 2010 provides for Developer Dashboard

a.) on - dispalys Developer Dashboard at the bottom of all the pages everytime
b.) off - it will disable the Developer Dashboard
c. ) onDemand - displays  the Developer Dashboard on click of an icon , at top-right corner of  the page.Developer Dashboard will be at the bottom of the page .

Note : Below is the example showing onDemand mode powershell script

$contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dashboardSetting = $contentService.DeveloperDashboardSettings
$dashboardSetting.DisplayLevel =[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$dashboardSetting.Update()

3. Execute the above script on Sharepoint 2010 Poweshell . 

4. An icon at the  top-right corner of the page will gets appear .


 5. Click the icon , now  you can see your Developer Dashboard at the bottom of the page .