Friday, September 19, 2008

Code snippet to get all installed languages from sharepoint server Farm


I had a requirement to display all installed languages of a SharePoint server farm in a DropDownList.

Regional Settings of SPWeb has a property named "SPWeb.RegionalSettings.InstalledLanguages", which returns language collection of type
"SPLanguageCollection". The following are the properties of "SPLanguage" instance.





Use the "Display Name" property to get the language display name ex. English and "LCID" property to get the locale ID ex. 1033(for English).
See the below code snippet, which will be used to get the installed languages from a SharePoint server farm.



Hope this will be helpful

Thursday, July 17, 2008

Programmatically uploading site templates to site template gallery

I had a requirement to upload site templates to site collection’s site template gallery using SharePoint object model. See the code snippet below, which will be helpful to upload site templates to site template gallery.



This code uses a configuration file, which has a custom section called “SiteTemplatesSection”. This custom section holds the physical path of each site template.

Friday, July 4, 2008

Programmatically Creating Site Collection in SharePoint

It is possible to create site collections programmatically. The Site Collection creation can be accomplished in the following ways

1) Using SharePoint Object Model
2) Using Central Admin’s Admin Web Service

Creation Site Collection using SharePoint Object Model

See the following code snippet, which uses SharePoint Object Model to create site collection.



Creating Site Collection using Admin Web Service

The Admin Web Service of Central Admin has the following web methods



The following code snippet uses “CreateSite” web method to create a site collection.
After the successful creation of site collection, this web method returns the URL of the newly created site.

Thursday, May 29, 2008

Programmatically adding data to SharePoint List’s Choice column

SharePoint has a column type called “CHOICE”. This column will be useful for presenting one of the field from the following
  • Dropdown List
  • Radio Buttons
  • Check Boxes (To Select Multiple Items)

Consider I’ve a list “Resource List” with following columns

Column Name ------ Type
Resource Name --> Single Line of Text
Languages Known --> Choice (C#, VB.NET, Java, C, C++) – Multiselect

Languages Known” is the CHOICE field (Check Boxes), to select multiple languages known by the resource.When adding new items to the Resouce List, notice that multiple items selected for the ‘Languages Known’ CHOICE column will be seperated by semi colan(‘;’).



I had a requirement to add the list item by code. I have used “ChoiceA;ChoiceB;..ChoiceN” for storing the ListItem’s multi-select CHOICE field. After adding ListItem by code, I have Edited the newly added item in the browser, but no check box has been selected for the item which was added by code.

Then after a little effort I found that the multi-select CHOICE data is stored as “;#ChoiceA;#ChoiceB;#...;#
See the below code for adding listitem to Resource List.


Below screen shows the newly added Item in the edit mode


Friday, April 4, 2008

Page Hit Counter in SharePoint

You would have seen many sites displaying page hit counters. To display this in SharePoint page, insert the “Hit Counter” web component from SharePoint Designer.

Open your site or your sites Master page to insert this component. For the demonstration purpose, I’ve use my default.aspx to insert the “Hit Counter” component. Once the page is opened in SharePoint Designer, place the cursor where you want to insert the hit counter. Go to Insert --> Web Component.




Click on the Web Component, this will display the available web components. You can find different types of other components readily available.



Click on the Hit Counter component, this will display different counter styles. Select any one style from the list. I have selected the below marked style.



Click on “Finish”, this will open the below Hit Counter Properties window.



You can even create your own Hit Counter. Use “Reset counter to” to reset the counter from a given number. To display fixed number of digits use “Fixed number of digits” property. Click on “Ok”, the hit counter will be inserted to your page. The below code will be inserted in your page to display the counter.



Now, preview your page from SharePoint Designer / a Web browser. You can see the Hit Counter incremented for each hit.



You can see the Hit Counter increments for each hit.

Tuesday, March 4, 2008

Creating SharePoint List using Office Excel

I had a requirement to create SharePoint lists using Excel sheet data. Luckily I notice that there is an option in Office Excel to create SharePoint list using excel data. Below screen shows the “Employee” data. I have used Office Excel 2003 for publishing excel list to SharePoint.


To create a SharePoint list, select the excel data then go to Data --> List --> Create List. This will create a List in Excel. If you are using Office Excel 2007 then use this reference.

Select the created list in Excel sheet and go to Data --> List --> Publish List. This will brings up a popup for publishing the created list to a SharePoint site.

Use this popup to input information like “Address” of the site, provide list a name and Description.

Click on Next, This will brings up the column and associated data type information. To publish excel data to a SharePoint list, Excel force columns to use certain types.

Click Finish to publish list to SharePoint.


Now, open the published site and add the newly created “Employee” list to the page. Below screen shows the Employee List which is created from Office Excel.
This approach will help to create SharePoint list from Office Excel with minimal effort.

Thursday, February 7, 2008

Windows UI for STSADM

Those who have used SharePoint for developing applications, they might have used STSADM executable. Here is an interesting utility that gives a UI for STSADM. This utility is developed as a windows application. It has a dropdown that displays all the STSADM options. Once a specific option is selected from the dropdown, it displays textboxes for various parameters.

See this post to download, to know more about STSADMWin utility.