Archive for June, 2011

Creating custom group for SharePoint web parts programmatically

June 24, 2011 1 comment

In last blog i discussed how to create new group / custom group or category for SharePoint web part(s).
Into this will discuss how to create the group / category programmatically.

For that purpose i have created a feature and in feature reciever (.cs) code is being applied when feature is activated.

//Getting the url of home site of site current site collection

using (SPSite aSite = new SPSite(SPContext.Current.Site.Url))
                    using (SPWeb aWeb = aSite.OpenWeb())

// Getting the web part gallery into galleryList object of SPList

                        SPList galleryList = aWeb.Lists[“Web Part Gallery”];

                        foreach (SPListItem anItem in galleryList.Items)
// There could have been many items into that gallery with properties null or no properties – check for them , as custom web part would have property [“WebPartTypeName”]

                            if (anItem.Properties != null && anItem.Properties.Count > 0)
// Check whether an item contains right properties , i am using name space to locate the right property as web part name can be changed by administrator but not the name space name as that would have been deployed by the developer.
                                if (anItem.Properties[“WebPartTypeName”].ToString().ToLower().Contains(“mycustomwebpart[name space]”))
                                       anItem[“Group”] = “My Custom Group”;
                                       anItem[“Description”] = anItem.Title + ” This is description of my custom web part”;


After that all the web parts comprising that name space would be added to “My Custom Group” with description.

Happy Coding.


Creating Custom Group for Web Parts in SharePoint [ UI ]

June 23, 2011 1 comment

There has always been many ways to do things in SharePoint.

1. Using UI [ SharePoint UI ].
2. Using OM [ SharePoint API’s , Object Model]
3. Using CMAL

I am going to use first two for this post. Well scenario came to me was to create a group for custom web parts which were already created.

  • The easiest way was to go to Site Actions from home site of Site Collection then to Site Settings.

Site Actions

  • Then to Web parts under the Galleries section

Site Actions

It would open a web part gallery of that site collection including OOB [out of the box] web parts and those custom web parts which have been populated to web part gallery.

6-23-2011 11-58-20 PM

Highlighted web parts are mine custom created web parts which are have been populated to web part gallery.

  • Web part Alpha
  • Web part Beta
  • Web part Gama

Now while adding them on site i would see them in Miscellaneous section / group.

6-24-2011 12-01-57 AM

One way is to create new group from UI , and then they would be shown into that group. For that we just need to click on edit button of the desired web part and give an appropriate group name.

6-24-2011 12-32-30 AM

In Group field of web part gallery , select specify your own Group value , in my case i mentioned My Custom Group. After doing so you would be able to categorize your web part(s).

6-24-2011 12-36-57 AM

For creating the web part group programmatically , please follow my blog Creating Custom Group for web parts programmatically.

SharePoint Localization, Multi Lingual Messages using Resource files.

June 20, 2011 3 comments

SharePoint is complete portal which covers all the basic and extensive needs for business, it’s one of the best content management tool of the era. One of its amazing functionality is SharePoint’s localization.

Let’s start with creating new sample project in VS2008.

1. Sample WSP Project named as Localization is created, I am using WSP Builder Extension provided by Microsoft for SharePoint development. Into it Resource folder is created which will contain clip_image002[4]resource files used for this project, and when it will be deployed they will be added into Resource folder of 12 hives.

2. Adding Resource file into Resource folder created. Two resource files have been added and for them Name and value have also been added to them, Names of resource files are Resource_EN and Resource_AR.


3. Name column of resource files should comprise similar values in all resource files and Value column would be changed as per language.




4. Sample web part has been created which would just display the text “This is an example of localization”.

5. If site is in English then message would be in English, if site is in Arabic then message would be in Arabic.

6. Code to get the current culture and resource file is as follow.

protected override void CreateChildControls()
if (!_error)
           //Getting the current culture [Locale ID].
            int intLCID = System.Threading.Thread.CurrentThread.CurrentUICulture.LCID;

Label lblWelcomeText = new Label();

//General_Text is the name of value which is similar in both resource files

//Calling function getLocalizedValue()

lblWelcomeText.Text = getLocalizedValue(“General_Text”, intLCID);


catch (Exception ex)




public string getLocalizedValue(string strInput, int intLCID)

// Function to retreive specified Language Variation Value

string strLocalizedValue = “”;
if (intLCID == 1033) { // Locale for English.

LocalizedValue = Microsoft.SharePoint.Utilities.SPUtility.GetLocalizedString(“$Resources: ” + strInput, “Resource_EN”, (uint)intLCID);


else if (intLCID == 1025) // Locale for Arabic.

strLocalizedValue = Microsoft.SharePoint.Utilities.SPUtility.GetLocalizedString(“$Resources: ” + strInput, “Resource_AR”, (uint)intLCID);

return strLocalizedValue;

Note: – I have Arabic and English language packs installed in my machine, that’s why representing their locales. This blog helped me a lot to perform this localization work.

English – Locale 1033

Arabic – Locale 1025

Hope this would help you too, Stay blessed.

Water marking for asp:textbox using javascript

A while ago i had a task to implement water mark on asp:textbox , well a short one but its always good to have the tasks which are not done before as they provides room for improvement and learning. In my opinion its not bad to learn even a single character a day .

Simple javascript function to deal in.


var text = document.getElementById(‘<%=txtExample.ClientID %>’).value;



document.getElementById(‘<%=txtExample.ClientID %>’).value= ;



function addWaterMark()

{ if(document.getElementById(‘<%= txtExample.ClientID %>’).value== )


document.getElementById(‘<%= txtExample.ClientID %>’).value=“Example C:\\FileName.p12”;




ToolTip=”Type full path of certificate including extention.”
onBlur=”addWaterMark()”>Example C:\Certificate.p12</asp:TextBox>


Javascript functions are called on events

  • onClick=”clearWaterMark()”
    //Checks if there is text in textbox starting with “Example” then clearing that.
  • onBlur=”addWaterMark()” // Checkis if there is no text in textbox then adding the text to textbox


Happy Coding J

How to display the password even textmode=”password” to textbox again?

June 2, 2011 4 comments

Few days back i was trying to get  stored password  into the ‘asp:textbox’  with textmode=”Password”.

I just wanted to see the stored password , like there are some scenarios where you need to show the stored password “NOT Text” but  in “* * * * ..”.

In my case, Initially password entered in txtPassowrd was stored in xml and i was required to get the password from xml and display the password in the textbox.

As there are many scenarios in which we need to show password again, hmmm as in update profile cases.

After some R&D , finally solution was in my arms :).

Solution to this was in just one line :).


just pass the text [stored password] to “password” and it will work for you.