Monday, July 29, 2013

How to determine SharePoint 2007 versions installed in server

This is quick guide to determine MOSS 2007 versions. I'm writing this post share knowledge because it took while to find out Service Pack versions which are installed on MOSS 2007 servers.

1. Go to Central Admin.
2. Then go to "Operations".
3. Select "Servers in farm" under Topology and Services category.
4. You can see the version of the SharePoint.


5. Follow below table to find out which version of SharePoint/Service pack installed on the server.

Version NameVersion NumberKB
First Release Version (RTM) 12.0.0.4518 N/A
Service Pack 1 12.0.0.6219 KB936988
Service Pack 2 12.0.0.6421 953338
Service Pack 3 12.0.0.6606 2526305

Friday, July 12, 2013

Cannot connect SPD 2013 to SharePoint 2013 online public site

We cannot connect to the SharePoint online 2013 public site using SharePoint Designer 2013. Hovever we can connect to the private silte collections via SPD2013.

Try below steps to connect to the private site collections.

  • Open the SPD 2013
  • Click open site in SharePoint desinger and give the private site collection address.(Make sure to add https instead of http)
  • Then give the online account credentials to login in to the site.

Thursday, June 27, 2013

Adding descriptive attribute to Enumerations in C#

Enumerations allows to add constants to be declare in the group. Main idea behind the enums are to make code more readable and maintainable. However these enum names are not suitable for display to the end user. This is most obvious when working with constants that combine two or more words, as no spaces, punctuation or other special characters are permitted.

Ex: enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri},
      enum Mode {Create, Delete, Modify}


If we can add description to each enum value then we can display the particular description instead of enum value. This article will focus on adding descriptive attribute to enum using extension method.



Step 1:
Create sample enum like below which is use to store form name categories and add following directive 

using System.ComponentModel;
(To add the descriptive attribute for each enum we should use above directive)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace EnumExample
{
    public enum FormCategory
    {
        RegistrationForm,
        DisplayClient,
        DeleteClient,       
        EditClient,
        AddNewClient,
    }
}






Step 2 :
Then add the descriptive attribute to each enum which is going to display to end user.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace EnumExample
{
    public enum FormCategory
    {
        [Description("Client Registration Form")]
        RegistrationForm,

        [Description("Display Client Information Form")]
        DisplayClient,

        [Description("Delete Client Form")]
        DeleteClient,

        [Description("Edit Existing Client Form")]
        EditClient,

        [Description("Add New Client Form")]
        AddNewClient,
    }
}




Step 3 :
Mechanism behind displaying enum description instead of enum value is .Net Reflection. The extension method will use reflection to examine the values in any enumeration and look for the Description attribute. Where present, the description will be returned. If the description is absent, the constant name will be returned instead.

Create static  class called EnumExampleExtensions.cs and add following directives,
using System.Reflection;
using System.ComponentModel;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace EnumExample
{
    public static class EnumExampleExtensions
    {
    }
}





Step 4:
Create static extension method Description which takes enum as parameter  like below.

public static string Description(this Enum enumValue)
{
            var enumType = enumValue.GetType();
            var field = enumType.GetField(enumValue.ToString());
            var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
            return attributes.Length == 0
                ? enumValue.ToString()
                : ((DescriptionAttribute)attributes[0]).Description;
}

In above code take the enum value and then resolve its description. GetField method is called, passing the name of the enumeration value provided in the method's parameter. This obtains the field information for the value. Finally check the description attribute and if attribute contains description return the description if not return the enum constant name.

Step 5:
Now it's time to test the code. I'm using console application for test the code.

Code :
Console.WriteLine(string.Format("Enum Value{0}", 
FormCategory.RegistrationForm.ToString()));

Console.WriteLine( 
string.Format("Enum Description{0}", 
FormCategory.RegistrationForm.Description()));
Console.ReadKey();

Output: