Thursday, August 25, 2011

Quick Notes: How to Detect the Installed Edition of SharePoint 2010

Many times it is required to know the current edition of SharePoint 2010 installed.
If the behavior of your custom application depends on the installed SKU of Microsoft SharePoint Server 2010, you can determine which SKU of SharePoint Server 2010 is installed locally by using the Power shell command and GUID of SharePoint 2010 Editions.
In this topic I will explain the how to get current edition of SharePoint 2010.
1.      You can get GUID of installed SharePoint 2010 from registory within the registry key HKLM\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\InstalledProducts.
2.      Or You can also use the PowerShell command get-spfarm | select Products to output GUIDs for the installed SKUs.
3.      As you get the GUID then you can check it with following table.
SharePoint 2010 Edition
SharePoint Foundation 2010
Search Server Express 2010
SharePoint Server 2010 Standard Trial
SharePoint Server 2010 Standard
SharePoint Server 2010 Enterprise Trial
SharePoint Server 2010 Enterprise
Search Server 2010 Trial
Search Server 2010
Project Server 2010 Trial
Project Server 2010
Office Web Companions 2010

Thursday, August 18, 2011

Digital Image Processing - Image Watermarking in C# and

In Today's internet world we see many images, photos, backgrounds etc. we can easily copy and paste them. But we don't know the actual creator of this images.

In this post i am not talking about SharePoint, it's all about C# coding. Just wanted to memorize the old things.

So lets do it....

Image Watermarking - Digital watermarking is the process of embedding information into a digital signal which may be used to verify its authenticity or the identity of its owners, in the same manner as paper bearing a watermark for visible identification. (Thank you wikipedia for this definition.)

I have created a web application that will demonstrate how to create a watermarked image with Text and Logo.

1. Create a Web Application Project in Visual Studio

2.Create layout in Aspx page.

3. Create function called GenerateWatermarkedImage()  and add following code in it.

Web.config file AppSettings
<appSettings >
    <add key="WatermarkImagePath" value="\Images\watermark.gif"/>
    <add key="SampleImagePath" value="\Images\SampleImage.jpg"/>
    <add key="TragetImagePath" value="\Images\TragetImage.jpg"/>

Namespaces used
using System;
using System.Configuration;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Web;

GenerateWatermarkedImage() Function
public void GenerateWatermarkedImage()
            // Load Source Image
            String strSourceImagePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["SourceImagePath"]);
            Image imgSource = Image.FromFile(strSourceImagePath);

            //Create New Bitmap Image
            int socWidth = imgSource.Width;
            int socHeight = imgSource.Height;
            Bitmap bmPhoto = new Bitmap(socWidth, socHeight, PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(72, 72);
            Graphics grPhoto = Graphics.FromImage(bmPhoto);

            //Load Logo Image
            String strLogoImagePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["LogoImagePath"]);
            Image imgLogo = new Bitmap(strLogoImagePath);
            int logoWidth = imgLogo.Width;
            int logoHeight = imgLogo.Height;

            //Step #1 - Watermark Text
            grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
                new Rectangle(0, 0, socWidth, socHeight),

            //Determine the largest possible size for WaterMark Text Message
            int[] sizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };
            Font crFont = null;
            SizeF crSize = new SizeF();
            string strWaterMarkText = TxtWatermark.Text;
            for (int i = 0; i < 7; i++)
                crFont = new Font("arial", sizes[i], FontStyle.Bold);
                crSize = grPhoto.MeasureString(strWaterMarkText, crFont);

                if ((ushort)crSize.Width < (ushort)socWidth)

            //String Alignment to Center
            int yPixlesFromBottom = (int)(socHeight * .05);
            float yPosFromBottom = ((socHeight -
                       yPixlesFromBottom) - (crSize.Height / 2));
            float xCenterOfImg = (socWidth / 2);

            StringFormat StrFormat = new StringFormat();
            StrFormat.Alignment = StringAlignment.Center;

            //Draw the WaterMark string at the appropriate position
            SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));

                new PointF(xCenterOfImg + 1, yPosFromBottom + 1),

            SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));

                new PointF(xCenterOfImg, yPosFromBottom),

            //Step #2 - Watermark Logo
            Bitmap bmWatermark = new Bitmap(bmPhoto);
            bmWatermark.SetResolution(imgSource.HorizontalResolution, imgSource.VerticalResolution);

            Graphics grWatermark = Graphics.FromImage(bmWatermark);

            //Translucent watermark
            ImageAttributes imageAttributes = new ImageAttributes();
            ColorMap colorMap = new ColorMap();

            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
            ColorMap[] remapTable = { colorMap };

            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            //Change the opacity of the watermark
            float[][] colorMatrixElements = {
                        new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
                        new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
                        new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
                        new float[] {0.0f,  0.0f,  0.0f,  0.3f, 0.0f},
                        new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
            ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
            imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            //Draw the watermark
            int xPosOfWm = ((socWidth - logoWidth) - 10);
            int yPosOfWm = 10;

                new Rectangle(xPosOfWm, yPosOfWm, logoWidth,

            //Replace the original Image with the new Bitmap
            imgSource = bmWatermark;

            //Save Watermarked Image
            String TragetImagePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["TragetImagePath"]);

            ImgWatermarked.ImageUrl = ConfigurationManager.AppSettings["TragetImagePath"];

4. Watermarked Image

Wednesday, August 17, 2011

SharePoint 2010 jQuery: List Scrolling View with Frozen Header


Many times SharePoint List has huge amount of records (Number of items) and it’s hard to scroll out the view. Also while scrolling the page we cannot determine which information is from which column.


By simple applying CSS we can achieve the Frozen Headers like Excel Sheet. And for achieving the same we use JQuery.


1. Go to List View Page and Html Form Webpart on the same page.
2. Copy Following code in Html Form Webpart. Just replace the LISTID and VIEWID (Highlighted in yellow color).

<script type="text/javascript" src="/Style Library/jq.Smoothness/js/jquery-1.5.1.min.js"></script>
<style type="text/css">
.DataGridFixedHeader { position: relative; top: expression (this.offsetParent.scrollTop); background-color: gray;}
<script type="text/javascript">


var $table = $("TABLE[ID^='{F1D2645C-4CC3-458C-BC93-CBCFECD12171}-{5AB46E0C-D38F-4FF2-BBE0-0D485CC351E9}']:first","#MSO_ContentTable");

$table.wrap("<DIV style='OVERFLOW: auto; HEIGHT: " + (screen.height-400) + "px'></DIV>");

$("", $table).addClass("DataGridFixedHeader");



For IE8 and IE9 browsers, require change in CSS class .DataGridFixedHeader  as follows.
 position: absolute;

Tuesday, August 9, 2011

Change look and feel of SharePoint Page using JQuery or Apply business logic to SharePoint List Forms using JQuery

As SharePoint 2010 gets popular, more and more scenarios are coming which most of required customization.
As we know SharePoint 2010 provides many options to customize the SharePoint Website, some of listed below…
1.    Visual Studio Development
2.    SilverLight Devlopment
3.    ECMA Script Development
4.    JQuery

In this post I am exploring the JQuery Development possibilities in SharePoint 2010.
As jQuery is a fast and concise JavaScript Library. We can easily give dynamic look to SharePoint Website and can also add custom business logic.
Let start the demonstration….

Take a scenario that we have to create Employee Registration Form with Tabular look and also enable disable tabs according to check box or radio button selection.

1.    First of all Download JQuery from

2.    Extract downloaded zip file and Copy all files into SharePoint Site (You can copy all files to Document Library or Can do Drag and drop using SharePoint Designer)

3.    Add following JQuery References to master page before </head> tag.

 <!--JQuery References --> 
<link type="text/css" href="jquery-ui-1.8.15.Redmond/css/redmond/jquery-ui-1.8.15.custom.css" rel="stylesheet" />     
<script type="text/javascript" src="jquery-ui-1.8.15.Redmond/js/jquery-1.6.2.min.js"></script> 
<script type="text/javascript" src="jquery-ui-1.8.15.Redmond/js/jquery-ui-1.8.15.custom.min.js"></script>

4.   Create SharePoint List.
      For demo purpose I have created Employees List and added 5-8 columns.

5.    Create a new list Form of type New Item.(You can set it as default)

6.   Edit List form in Advanced Mode.

7.    As we want to display form in tabular, so we have to add JQuery Tab schema as follows ..

<!-- Tabs -->
<h2 class="demoHeaders"> Employee Registration Form</h2>
<div id="tabs">
        <li><a href="#tabs-1">Personal</a></li>
        <li><a href="#tabs-2">Contact</a></li>
        <li><a href="#tabs-3">Office</a></li>
        <li><a href="#tabs-4">New Hire</a></li>
        <li><a href="#tabs-5">Contractor</a></li>
        <li><a href="#tabs-6">Desktop</a></li>
        <li><a href="#tabs-7">Laptop</a></li>   
    <div id="tabs-1">
                   <table border="0" cellspacing="0" width="100%">

    <div id="tabs-2">
                   <table border="0" cellspacing="0" width="100%">

    <div id="tabs-3">
                   <table border="0" cellspacing="0" width="100%">


8.    Modify JQuery Schema, Add columns to respective tab DIV;

 9.    Open newly create list form in browser; Select edit page from Page Tab.
        Add "HTML Form Web Part", go to WebPart properties; add following code using "Source Editor".

<script type="text/javascript">
                // Tabs
<script type="text/javascript">
    $(document).ready(function () {
        $('#tabs').tabs("option", "disabled", [3, 4, 5, 6]);
                  function () {
                      this.onclick = function () { RadioBtnEvent(this) };
                  function () {
                      this.onclick = function () { CheckBoxEvent(this) };

    function RadioBtnEvent(RedioBtn) {
        if (RedioBtn.parentElement.title == "New Hire") {
             if (RedioBtn.checked) { EnableTab(3); DisbleTab(4); }
            else { DisbleTab(3); }
        else if (RedioBtn.parentElement.title == "Contractor") {
             if (RedioBtn.checked) { EnableTab(4); DisbleTab(3); }
            else DisbleTab(4);
        }else {

    function CheckBoxEvent(CheckBoxCtrl) {
        if (CheckBoxCtrl.parentElement.title == "Desktop") {
           if (CheckBoxCtrl.checked) EnableTab(5);
            else DisbleTab(5);
        else if (CheckBoxCtrl.parentElement.title == "Laptop") {
           if (CheckBoxCtrl.checked) EnableTab(6);
            else DisbleTab(6);

    function EnableTab(TabIndex) {
        $('#tabs').tabs('enable', TabIndex);

    function DisbleTab(TabIndex) {
        $('#tabs').tabs('disable', TabIndex);

10.    Output

Conclusion: We can use JQuery in SharePoint 2010; And it takes less time to use JQuery in SharePoint but more time to post a blog on it.