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
GUID
SharePoint Foundation 2010
BEED1F75-C398-4447-AEF1-E66E1F0DF91E
Search Server Express 2010
1328E89E-7EC8-4F7E-809E-7E945796E511
SharePoint Server 2010 Standard Trial
B2C0B444-3914-4ACB-A0B8-7CF50A8F7AA0
SharePoint Server 2010 Standard
3FDFBCC8-B3E4-4482-91FA-122C6432805C
SharePoint Server 2010 Enterprise Trial
88BED06D-8C6B-4E62-AB01-546D6005FE97
SharePoint Server 2010 Enterprise
D5595F62-449B-4061-B0B2-0CBAD410BB51
Search Server 2010 Trial
BC4C1C97-9013-4033-A0DD-9DC9E6D6C887
Search Server 2010
08460AA2-A176-442C-BDCA-26928704D80B
Project Server 2010 Trial
84902853-59F6-4B20-BC7C-DE4F419FEFAD
Project Server 2010
ED21638F-97FF-4A65-AD9B-6889B93065E2
Office Web Companions 2010
926E4E17-087B-47D1-8BD7-91A394BC6196

Thursday, August 18, 2011

Digital Image Processing - Image Watermarking in C# and Asp.net

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"/>
</appSettings>

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;
            grPhoto.DrawImage(
                imgSource,
                new Rectangle(0, 0, socWidth, socHeight),
                0,
                0,
                socWidth,
                socHeight,
                GraphicsUnit.Pixel);

            //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)
                    break;
            }

            //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));

            grPhoto.DrawString(
                strWaterMarkText,
                crFont,
                semiTransBrush2,
                new PointF(xCenterOfImg + 1, yPosFromBottom + 1),
                StrFormat);

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

            grPhoto.DrawString(
                strWaterMarkText,
                crFont,
                semiTransBrush,
                new PointF(xCenterOfImg, yPosFromBottom),
                StrFormat);

            //#####################################
            //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;

            grWatermark.DrawImage(imgLogo,
                new Rectangle(xPosOfWm, yPosOfWm, logoWidth,
                                                 logoHeight),
                0,
                0,
                logoWidth,
                logoHeight,
                GraphicsUnit.Pixel,
                imageAttributes);

            //Replace the original Image with the new Bitmap
            imgSource = bmWatermark;
            grPhoto.Dispose();
            grWatermark.Dispose();

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

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

4. Watermarked Image


Wednesday, August 17, 2011

SharePoint 2010 jQuery: List Scrolling View with Frozen Header


Problem:

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.

Solution:

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

Implementation: 

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;}
-->
</style>
<script type="text/javascript">

$(function(){

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

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

<!--FROZEN HEADER ROW-->
$("TR.ms-viewheadertr:first", $table).addClass("DataGridFixedHeader");

});

</script>

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

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 jqueryui.com

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">
    <ul>
        <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>   
              </ul>
    <div id="tabs-1">
                   <table border="0" cellspacing="0" width="100%">

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

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

                   </table>
              </div>
</div>

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">
            $(function(){
                // Tabs
                $('#tabs').tabs();                           
            });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        //debugger;
        $('#tabs').tabs("option", "disabled", [3, 4, 5, 6]);
        $('input:radio').each(
                  function () {
                      this.onclick = function () { RadioBtnEvent(this) };
                  }
              );
        $('input:checkbox').each(
                  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 {
            DisbleTab(5);
            DisbleTab(6);
        }
    }

    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);
    }
</script>

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.