Monday, November 16, 2009

Site Navigation in SharePoint

is very important in any application. Navigation provides the way for the user to travel with in application.

Today I'll talk about Site Navigations in SharePoint.

  1. Global navigation (typically the top navigation)

  2. The current navigation (typically the left - hand navigation)

We can change the navigation by below two ways.

  1. Browser - Based Customizations

Publishing sites have a navigation customization capability through the browser. Navigating to the site’s Site Settings page and selecting Navigation under option. The Look and Feel section brings the user to the Site Navigation Settings page. From this page the site can be configured to include or exclude either sub sites and/or pages from the main navigation. In addition to the scoping options, owners can also select to manually or automatically sort navigation.

2. Changing Navigation Programmatically with the API
Below are custom Properties available with API.

1>  IncludeSubSites and IncludePages properties accept one of three values:
1.1> Always, 1.2> PerWeb, and 1.3>Never.

2> IncludeHeadings and IncludeAuthoredLinks properties are Boolean values that enable the site administrator to allow or block the inclusion of custom links and headings in the navigation.

We can add a new navigation code by using “Microsoft.SharePoint.Navigation.SPNavigationNode” class and then we need to add them in proper navigation collection.

Snippets code

SPWeb site = SPContext.Current.Web;

// get a reference to the top navigation

SPNavigationNodeCollection topNavigation = site.Navigation.TopNavigationBar;

// or get a reference to the Quick Launch navigation

// SPNavigationNodeCollection quickLaunchNav = site.Navigation.QuickLaunch;

// create new drop down menu in the navigation

SPNavigationNode newMenu = new SPNavigationNode(“External Links”, “”, false);

// add the new menu to the end of the top nav bar


// add a custom link

newMenu.Children.AddAsLast(new SPNavigationNode(“Google”,“”,true));

Let’s try something new into SharePoint other then out of the box functionality!

Friday, November 13, 2009

Double Hop Problem in SharePoint

Hello Friends,

I have faced problem when I built a web part which takes a main file and from that file I need to access all files of respective directory by directory.getfiles method and every time I got error “Could not find a part of this path (path)” .

I tried so many other solutions like I used windows Identity but didn’t get success. It seems that if SharePoint web application hosts on another server and if we try to access file from another local system then it’s not working.

At the last I have found out that it’s related to Double Hop Problem.

According to Microsoft KB article:

The double-hop issue is when the ASPX page tries to use resources that are located on a server that is different from the IIS server.

I read about Double Hob problem into SharePoint, and solved by using Kerberos authentication.

I have followed this link to solved my problem:

Enjoy Debugging!
Disha Shah

Wednesday, November 4, 2009

Some Information on Web Parts and AJAX Web Parts

Web Parts

Web Part pages are pages that host Web Parts. Technically speaking a  Web Part is a class that inherits from the WebPart class defined in System.Web.UI.WebControls. ASP.NET 2.0 introduced  a Web Part infrastructure that requires exactly one WebPartManager control and one or more WebPartZone controls. The WebPartManager manages Web Part Instances and supports serialization of web part data so that it can be stored in the ASP.NET services database.  WSS 3.0 uses a control derived from WebPartManager called SPWebPartManager.

SPWebPartManager persists this data in the content database instead of the services database.  SPWebPartManager is already defined in the default.master page, so when you create a site page that links to this master page, this control is automatically added to your page.  Therefore you only need to add WebPartZones to create a Web Part.

Web Parts are the fundamental building block of SharePoint’s user interface.  They allow the SharePoint developer to achieve the goal of creating reusable components for business users which is, in many organizations, the primary task of a SharePoint developer.   Many Web Parts already exist  which may meet the needs of business users.

Web Parts make it possible for changes to customized site pages to be seen by all users on that site.  They also allow individual users to create personalized changes that only they can see. So Web Parts support both  customization and of personalization. Web Parts support customization of site pages but not application pages.   Customizing web parts does not require customization of the pages that host them.  All customization and personalization data are hosted inside the content database and is managed by the web part infrastructure.

To create a Web Part page, you must inherit from WebPartPage which is defined in Microsoft. SharePoint.dll, and you must add one or more WebPartZone controls.   One way to add a web part instance to a web part zone is to add an AllUsersWeb Part element to a feature.xml file.  A second method is to write code against the WSS object model  which may be required for more sophisticated processing.

Web Parts render inside what is know is chrome, the common user interface elements such as formatted title bar and borders around the web part’s body.  Chrome is rendered by the application framework (in this case WSS).

In SharePoint, Web Parts exist entirely within the content database and they are processed in safe mode. They should be as autonomous  as possible and should be compiled into a DLL.  They run under security settings that are defined in the web.config file and for this reason they should be deployed in solutions since Solution packages should correctly specify trust settings for deployment.

A Web Part Verb is an action that is rendered in the Web Part menu by the Web Part framework as a part of the chrome rendered around the control.  Web Part Connections are frequently used for master/detail records in Web Parts.

One useful building block for a Web Part is the SPGridView control which can be bound to SPDataSource to retrieve data from SharePoint lists.


AJAX Web Parts

AJAX Web Parts use several technologies to achieve an increased level of responsiveness once possible only in rich-client applications.  These technologies include:  object-oriented JavaScript, asynchronous data requests utilizing the XML HttpRequest object, XML data streams, Extensible Stylesheet Language Transforms (XSLT),  and dynamic manipulation of the HTML Document Object Model (DOM).

One of the main benefits is that smaller components are rendered in response to a user’s actions rather than rendering the entire page as a unit.   The AJAX approach includes a client runtime based on the ASP.NET AJAX library.  Instead of one large data stream being processed in the main request/response, individual components are responsible for their processing and can be individually refreshed based on user actions and events.   The user can continue working while individual AJAX components are processing.

Designing and building AJAX Web Parts is quite complex and this topic is definitely beyond the scope of this document.

Disha Shah

Step by Step Tutorial for How to create and implement custom field type in SharePoint 2007

Hi Everyone

What is Custom field Type in SharePoint ? Why we need Custom field type?

We have sometime instances where our business data does not fit to the field types included in Windows SharePoint Services or some situations where we need to further customize those general field types. Windows SharePoint Services enables you to create custom field types. These custom fields can include custom data validation and custom field rendering. You can also customize the way that variable properties of your custom field types are processed and rendered when users set property variables and create new columns that are based on your custom field type.


We need Country and State Columns in SharePoint List and when user selects Country we need to populate states according to that, How to implement this functionality If we need to use Country and State drop down again and again in number of places in SharePoint lists then we need to use Custom Field Type and add that Custom Field in SharePoint List.

Today I’ll show you how to create and implement Custom Field Type step by step.
  1. Open Microsoft Visual Studio, Go to File-->New-->Project.
  2. In the New Project dialog box, select Class Library from the Templates box, give it a name and location, then click OK.
  3. Add Reference of Microsoft.SharePoint assembly, and then click OK.
  4. Make the project as strong name key file.
  5. Now rename class.cs with CountryStateField.cs
  6. Creating a class for Custom field Type
  7. Create a field definition Schema XML file
  8. Create a class which contains FieldTypeValue.
  9. Create a class which is used for to display that , fieldcontrol.

Let us go through every step in detail one by one.

Step No 6 :Creating a Custom Field Type
The first step in creating a custom field type and field control is to create the field type class — the hub of everything related to the field. All field types must inherit from the Microsoft.SharePoint.SPField class or one that is derived from it.

Sample of Code

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

namespace Sample.FieldType


class CountryRegionField:SPFieldMultiColumn

public {

public CountryStateField(SPFieldCollection fields, string fieldName): base(fields, fieldName) { }

public CountryStateField(SPFieldCollection fields, string typeName, string  displayName): base(fields, typeName, displayName) { }

public override object GetFieldValue(string value)


if (string.IsNullOrEmpty(value))   return null;

return new CountryStateValue(value);


public override BaseFieldControl FieldRenderingControl




BaseFieldControl control = new CountryStateControl();

control.FieldName = this.InternalName;

return control;



public override string GetValidatedString(object value)


if (value == null)


if (this.Required) throw new SPFieldValidationException("Invalid value for this field.");

return string.Empty;




CountryStateValue field = value as CountryStateValue;

// if no value obtained, error in the field

if (field == null) throw new ArgumentException("Invalid value.");
// if it is required...

if (this.Required)


// make sure that both COUNTRY & State are selected

if (field.Country != string.Empty && field.State != string.Empty)

throw new SPFieldValidationException("Both are required.");




// else, even if not required, if one field is filled in, the other must beas well

if (!string.IsNullOrEmpty(field.Country))


throw new SPFieldValidationException("Both are required if one value is entered.");


return value.ToString();





Let us move to the next step , Create a xml file for Custom field Definition.

Step No. 7 : Creating a Custom Field Type Definition

With a field type class created, the next step is to create the field type definition that will make SharePoint aware of the field. This is done by creating an XML file in the [..]\12\TEMPLATE\XML Folder. When SharePoint starts up ,it looks at the [..]\12\TEMPLATE\XML folder and loads all the field type - defined files named fldtypes[_*].xml .

All the SharePoint fields provided in the WSS 3.0 install are found in the fldtypes.xml file. Other fields are added based on the MOSS 2007 installation. For instance, all the Publishing - specific fields are defined in the fldtypes.publishing.xml file.

CountryStateField definition (fldtypes _ CountryState.xml)

< ?xml version=”1.0” encoding=”utf-8” ? >

< FieldTypes >

< FieldType >

< Field Name=”TypeName” > CountryState< /Field >

< Field Name=”ParentType” > MultiColumn < /Field >

< Field Name=”TypeDisplayName” > Country, State < /Field >

< Field Name=”TypeShortDescription” > Country and state < /Field >

< Field Name=”UserCreatable” > TRUE < /Field >

< Field Name=”FieldTypeClass” > Sample.FieldType. CountryStateField,Sample.FieldType,Version=, Culture=neutral,  PublicKeyToken=e42a63991be18435 < /Field >

< RenderPattern Name=”DisplayPattern” >

< Switch >

< Expr > < Column / > < /Expr >

< Case Value=”” / >

< Default >

< Column SubColumnNumber=”0” HTMLEncode=”TRUE” / >

<HTML> <![CDATA[;]]></HTML>

< Column SubColumnNumber=”1” HTMLEncode=”TRUE” / >

< /Default >

< /Switch >

< /RenderPattern >

< /FieldType >

< /FieldTypes >
  • TypeName: This is the unique name of the field used when creating items such as site columns using a Feature. For example, if a site column were created that was based on the field type created in this chapter, the element manifest ’ s site element would look like the following (omitting the other required attributes):
  • ParentType: The parent type is the field type from which the custom field type is derived — in this case, SPFieldMultiColumn or just MultiColumn .
  • TypeDisplayName: This name is used to display the field type on pages such as the Site Column Gallery or a content type ’ s detail page.
  • TypeShortDescription: The short description is the string used to display the field type as an option when creating new site or list columns (the long radio button list under the new column ’ s title textbox).
  • UserCreatable: This Boolean property tells SharePoint whether the field type can be used in the creation of a column in a list by a user. When false , developers can still use the field type in sitecolumns within the definition of list templates created using Features.
  • FieldTypeClass: This contains the strong name of the field type class and the assembly containing the class. This is also referred to as the five - part name: namespace.type, Assembly,Version, Culture, PublicKeyToken .

The custom field type definition should be added to the Visual Studio project in the following location: \TEMPLATE\XML\fldtypes_ CountryState.xml .

Step no 8  Creating a Custom Field Value
One of the requirements of the ContryStateField custom field type was to store the data within a custom data structure. While it sounds a bit complex, it is actually very simple. The custom field value class is very handy with field types that are derived from the SPFieldMultiColumn field because data is stored in the SPFieldMultiColumn field as a special delimited string using ;# as the delimiter, and not just between two values but surrounding them ;#United States;#Florida;#

CountryStateValue.cs file containing the field value

using System;

using Microsoft.SharePoint;

namespace Sample.FieldType{

public class CountryStateValue : SPFieldMultiColumnValue {

private const int NUM_FIELDS = 2;

public CountryStateValue ()

: base(NUM_FIELDS) { }

public CountryStateValue (string value)

: base(value) { }

public string Country {

get { return this[0]; }

set { this[0] = value; }


public string State {

get {return this[1];}

set { this[1] = value; }




Step No 9 : Creating a Custom Field Control

The first piece in a custom field control is the control class. This class must inherit from the Microsoft.SharePoint.WebControls.BaseFieldControl class or one that derives from it. For the CountryStateField , the BaseFieldControl will work.

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint.WebControls;

using System.Web.UI.WebControls;

using Microsoft.SharePoint;

namespace Sample.FieldType


public class CountryStateControl : BaseFieldControl,IDesignTimeHtmlProvider


protected DropDownList _country;

protected DropDownList _StateSelector;

protected Literal _StateSelectorLiteral;

public override object Value {




CountryStateValue field = new CountryStateValue();

if (_country == null || _StateSelector == null )


field.Country = String.Empty;

field.State = String.Empty;




// set country value

if (_country.SelectedIndex == 0)

field.Country = String.Empty;


field.Country = _country.SelectedValue;

// set State value

if (_StateSelector.SelectedIndex == 0)

field.State = String.Empty;


field.State = _StateSelector.SelectedValue;


return field;





if (value != null && !string.IsNullOrEmpty(value.ToString()))


CountryStateValue field = new CountryStateValue(value.ToString());

_country.SelectedValue = field.Country;

if (_country.SelectedIndex > 0)

_StateSelector.SelectedValue = field.State;





private void SetStateControlVisibility(int countrySelectedIndex)


switch (countrySelectedIndex)


case 0: // if none selected

_StateSelector.Visible = false;

_StateSelectorLiteral.Visible = false;


default: sss

_StateSelector.Visible = true;

_StateSelectorLiteral.Visible = true;




protected void Country_SelectedIndexChanged(object sender, EventArgs e)






protected void ADDstatesdependsonCountry(int countrySelectedIndex)



//Code for Adding items to State dropdown depends on contry


void AddItesmsForContry()


//code for adding items to country dropdown


protected override void CreateChildControls()


if (this.Field == null || this.ControlMode == SPControlMode.Display ||this.ControlMode == SPControlMode.Invalid)



// get reference to Country selector

_country = new DropDownList();

_country.SelectedIndexChanged += new EventHandler(Country_SelectedIndexChanged);

_country.AutoPostBack = true;


_StateSelector = new  DropDownList();
_StateSelectorLiteral = new Literal();

//Add country ,state Selector and State Literal to control collection







Happy Coding :)

How to upload big size of documents to SharePoint site

When we upload documents to SharePoint Document Library from SharePoint GUI or from Customized web part if our document size is more than 50 MB, it will not allow us to upload the documents.

In this article, I will explain about how to resolve that problem!

We need to change configurations at two places.
  1. Web.Config :-
  • We need to make change for below two important thing.
  • NOTE: This change is very important when you upload document to SharePoint document library by using programmatically or from SharePoint Object Model Code by using Asp.NET File Upload control or HTML File Upload.

i. maximumRequestLengh: What is maximum size of File, a user can upload.

ii. Execution Timeout: it is very important because if it is less than upload time, upload of file operation can fail.

  • Open the Web.config file of this webapplication by going to Local Drive:\Inetpub\wwwroot\wss\VirtualDirectories\SharepointApplicationPortNumber(example 80)
  • Find < httpRuntime and replace that line with the following line.
2. Change in Central Administration site
  • Go to SharePoint 3.0 Central Administration -> Application Management
  • Under “SharePoint WebApplication Management”, we need to go into “WebApplication General Settings”.
  • Change the “SharePoint Web application” in which we need to make changes.
  • There is option called “Maximum Upload Size” - 50 MB is default value, make it 2047 value.
  • Click OK.
We are done!

Now user can upload more size of documents into SharePoint site.

Disha Shah

Friday, August 21, 2009

How to exclude fields from SharePoint ListFieldIterator Control

Here I am going to share with you a very small things but I think it’s very helpful. SharePoint Web Controls provides set of controls which we can use for generating our custom pages very easily without writing much custom code, there is control called “ListFieldIterator”, in which we need to specify which SharePoint List we are going to bind with controls and it will generate all controls related to SharePoint List.

In ListFieldIterator control if we want to exclude some fields from generated control, then we can use ListFieldIterator.ExcludeFields property, but when we have multiple fields for exclusion then we need to separate the fields with a semicolon and pound sign ";#" as separator, for single field we are using "." as separator.

SharePoint Web Controls rocks !!!

Thursday, August 13, 2009

SharePoint Master Pages and Branding

Today I’ll talk about master pages and branding fundamentals into SharePoint :)

Every WSS 3.0 site is provisioned with a special Master Page gallery which contains a master page template known as default.master. This file is deployed in the 12-hive under 12\TEMPLATE\GLOBAL. Each new WSS site provides an instance of default.master. It is possible to customize default.master, but if you do, it becomes unghosted and this can affect efficiently and scalability.

The default.master page contains controls (including links, menus, icons and navigation components), named placeholders, and delegate controls. Named placeholders are used to add unique contents to a page template of page instance that is linked to a master page. Delegate Controls provide a way to substitute elements into the master page layout that affect every site. Delegate Controls are changed via activating features; therefore modifications to delegate controls require no changes to the default.master or site pages that are linked to default.master.

WSS provides several standard controls to support navigation including the SiteMapPath control which populates a breadcrumb navigation menu to allow users to navigate from the current site upwards to the top-level site of current site collection. Navigation is based on the infrastructure provided by ASP.NET 2.0.

You can also create a custom master page template. To do this you must create the master page template itself, and then create a feature that provisions an instance of this master page in the Master Page gallery for a specific site. Finally you need to redirect site pages to use your custom master page instead of using default.master.

You can customized the look and feel of a site (brand it) by using Cascading Style Sheets.You can find standard language specific CSS files in \TEMPLATE\LAYOUTS\1033\STYLES.The primary file is called core.css. This file is scoped at farm level, so it is not a good idea to change it. Instead one way to change the look and feel is to use Themes which are found in TEMPLATE\THEMES.or we can create a custom.css file and put into TEMPLATE\LAYOUTS\1033\STYLES\<your folder>.Brand images are located in TEMPLATE\IMAGES

Keep writing!! 

Sunday, August 9, 2009

Sharepoint Page Types - Application and Site Pages

Hello Friends

SharePoint allows page ghosting, the ability to store a single copy of a page as a page template (on the file system). From which it creates page instances. Top level pages that are identical for many web applications are handled as ghostable pages, however once a page is customized, it becomes unghosted. The purpose of page ghosting is to improve efficiency and scalability. The idea is that if 100 websites need the same default.aspx page, then that page is handled very efficiently via page ghosting. Ghosted pages are compiled into a DLL which is kept in memory.

Since customized pages are numerous, it would take too much memory to compile each of them into a DLL and store them all in memory. SharePoint provides a mechanism that allows customized .aspx pages to be stored in the context database. For this to work SharePoint must be able to find the page in SQL instead of on the local drive. SharePoint provides SPVirtualPathProvider a class that abstracts the Page Parse. This class decides whether a page is ghosted or unghosted. Unghosted page must be individually parsed and loaded into memory.

SharePoint websites contain some special virtual directories: _layouts, _vti_bin, and _wpresources which are used by the WSS runtime. The physical location of these virtual directories is under web server extensions.

SharePoint supports application pages and site pages. Application pages can not be customized. They perform better and can contain inline code. You can create new application pages and integrate them into menus using CustomActions.xml elements. An application page is typically used in many websites. A good example of application page would be settings page which administrators can find in the Site Actions menu.

Application pages are deployed in the <12 hive>\TEMPLATES\LAYOUTS folder. Application pages are scoped at the farm level. They are used to provide much standard functionality for provisioning and administering sites.

Site pages can be customized and are unghosted. Although they must be retrieved from the content database, parsed, and then loaded into memory, unlike DLLs, they can be unloaded from memory too. Possibly this makes websites with a large number of pages because memory is freed up when pages are no longer needed.

The SPFile class is used to read and write to the contents of a site page. The SPFolder class supports a hierarchy of site pages.

Disha Shah

Saturday, August 8, 2009

How to attach/delete/upload files to SharePoint List Item using Object Model

Hello Friends

I have one requirement in which I need to develop a web part in which users can upload multiple documents to SharePoint List Item and they can see all uploaded files into data grid control, they also need facility for user to delete selected files, add new files from same control and also they can download files.

Here in this post, I am writing code for each functionality as per my requirements.

Snippet code of deleting attachment from SharePoint list item :

private void DeleteAttachment(int NodeID, String strFileName)
            SPContext.Current.Web.AllowUnsafeUpdates = true;

            SPListItem delItem = lstAudit.GetItemById(NodeID);
            SPAttachmentCollection atCol = delItem.Attachments;
            foreach (string strDelfileName in atCol)
                if (strDelfileName == strFileName)


        catch (Exception eDel)
            string errDel = eDel.Message;

Snippet code for downloading attachment from SharePoint List Item :

 private void DownloadAttachment(string FileName)
            string AttachmentURL = string.Empty;
            AttachmentURL = FileName;
            string strName = AttachmentURL.Substring(AttachmentURL.LastIndexOf("/") + 1);
            string sbURL = AttachmentURL.Trim();
            System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            Response.AppendHeader("Content-disposition", "attachment; filename=" + strName);
            Response.AppendHeader("Pragma", "cache");
            Response.AppendHeader("Cache-control", "private");
        catch (Exception eDwn)

Snippet code of uploading document to SharePoint List Item :

 protected void btnUpload_Click(object sender, EventArgs e)
            string fileName = "";
            string strExtensionName = "";

            fileName = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);

            if (fileName != "")
                strExtensionName = fileName.Substring(fileName.IndexOf(".") + 1);
                if (strExtensionName.Equals("webpart") || strExtensionName.Equals("dll") || strExtensionName.Equals("bat") || strExtensionName.Equals("exe"))
                    lblMessage.Visible = true;
                    lblMessage.Text = "Invalid fileName!!";
                    string _fileTime = DateTime.Now.ToFileTime().ToString();

                    string _fileorgPath = System.IO.Path.GetFullPath(FileUpload.PostedFile.FileName);

                    if (txtFileName.Text.Trim().Length > 0)
                        fileName = fileName.Replace(fileName.Substring(fileName.LastIndexOf("\\") + 1), txtFileName.Text) + "." + strExtensionName;
                    string _newfilePath = _fileTime + "~" + fileName;

                    string tempFolder = Environment.GetEnvironmentVariable("TEMP");

                    string _filepath = tempFolder + _newfilePath;

                    AddRow(fileName, _filepath, 0, true);

                lblMessage.Visible = true;
                lblMessage.Text = "Please Selct file Name";


        catch (Exception Ex)


    protected void dgdUpload_RowDeleting(object sender, GridViewDeleteEventArgs e)
        int recordToDelete = e.RowIndex;

        //dt = (DataTable)Page.Session["Files"];
        dt = (DataTable)ViewState["Files"];

        int cn = dt.Rows.Count;

        if (Convert.ToInt32(dt.Rows[recordToDelete].ItemArray[0]) != 0)
            DeleteAttachment(Convert.ToInt32(dt.Rows[recordToDelete].ItemArray[0]), dt.Rows[recordToDelete].ItemArray[1].ToString());


        //Page.Session["Files"] = dt;
        ViewState["Files"] = dt;
        dgdUpload.DataSource = dt;
    private void AddMoreColumns()

        dt = new DataTable("Files");

        dc = new DataColumn("ID", Type.GetType("System.Int16"));

        dc = new DataColumn("FileName", Type.GetType("System.String"));

        dc = new DataColumn("FilePath", Type.GetType("System.String"));

        //Page.Session["Files"] = dt;
        ViewState["Files"] = dt;

    private void AddRow(string file, string path, int ID, Boolean bolCheckForfiles)

        Boolean bolAddRow = true;
        //dt = (DataTable)Page.Session["Files"];
        dt = (DataTable)ViewState["Files"];
        if (dt == null)

        if (bolCheckForfiles)
            if (dt.Rows.Count > 0)
                foreach (DataRow drExistingrow in dt.Rows)

                    if (drExistingrow["FileName"].ToString() == file)
                        bolAddRow = false;
        if (bolAddRow)

            dr = dt.NewRow();


            dr["ID"] = ID;
            dr["FileName"] = file;
            dr["FilePath"] = path;



            //Page.Session["Files"] = dt;
            ViewState["Files"] = dt;

            dgdUpload.DataSource = dt;

            dgdUpload.DataBind();//bind in grid

            lblMessage.Visible = true;
            lblMessage.Text = "Same File Name already exists!!!";


    protected void dgdUpload_RowCommand(object sender, GridViewCommandEventArgs e)
        if (e.CommandName == "View")
            string file = e.CommandArgument.ToString();



        if (dt != null)

            int _dtcnt = dt.Rows.Count;
            foreach (DataRow dr in dt.Rows)

                Boolean bolAddAttachment = true;
                fileName = dr["FileName"].ToString();
                if (itmCorrectiveActionFinding.Attachments.Count > 0)
                    foreach (string strAttachedname in itmCorrectiveActionFinding.Attachments)

                        if (fileName == strAttachedname)
                            bolAddAttachment = false;

                if (bolAddAttachment)
                    string strFilepath = dr["FilePath"].ToString();

                    StreamReader sr = new StreamReader(strFilepath);

                    Stream fStream = sr.BaseStream;

                    contents = new byte[fStream.Length];

                    fStream.Read(contents, 0, (int)fStream.Length);


                    itmCorrectiveActionFinding.Attachments.Add(fileName, contents);



How to Integrate AJAX with Publishing SharePoint Site Templates

Hello Friends, 

When I have enabled AJAX with SharePoint into my site, I need to do lots of configuration changes into my site related to adding some new sections into web.config file, etc. 

This link is very useful; it’s giving us step by step instruction for how to integrate AJAX with SharePoint site. 

But I have figured out that we need to make some more changes into master page in which we have publishing SharePoint site templates, Collaborate SharePoint site template

We need to open master page of Collaboration Site Template and need to add below lines. 

<BODY scroll=”yes”>

  <form runat=”server”>

 <WebPartPages:SPWebPartManager runat=”Server”/>

 <asp:ScriptManager runat=”server”></asp:ScriptManager> 

Hope it will help to someone! 

Thanks and Enjoy!!!

How to display detailed error messages into SharePoint page

It happens most of time with everyone when they are working with SharePoint and gets error message is “An unexpected error occurred”, that’s very boring and frustrated error message into SharePoint page, which leaves a number of guesses and questions. 

If you would like to know what exact error description is, then we need to make following changes into our SharePoint web application web.config file. 

1> CallStack=”false” changed to CallStack=”true” 

2> <customErrors mode=”On” /> changed to <customErrors mode=”Off” /> 

Happy debugging :)

Saturday, July 25, 2009

How to Send Email from SharePoint object model by accessing Email Configuration from Central Admin

Here is example code for sending email from SharePoint object model, main part of code would be “SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address”, it will return mail server address which is assigned from SharePoint central administration site as per web application

Sample Code:

private void SendEmail()
SmtpClient client = LoadSmtpInformation();
catch (Exception Ex)

private SmtpClient LoadSmtpInformation()

string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
SmtpClient client = new SmtpClient(smtpServer);
client.UseDefaultCredentials = true;
return client;

private MailMessage BuildMailMessage()

MailMessage message = new MailMessage();

message.From = new MailAddress(SPContext.Current.Web.CurrentUser.Email);
message.To.Add(new MailAddress(User.Email));
message.IsBodyHtml = true;
message.Body = “Email Message”;

message.Subject = "Subject of Email";
return message;


Friday, July 24, 2009

How to write error message to SharePoint logs file

SharePoint object model gives us very good functionality and ability to write our customize error messages into SharePoint logs file.

We can pass our error string into LogString method from Microsoft.Office.Server.Diagnostics.PortalLog class and it will write error into logs file.

Sample Code:





catch (Exception Ex)
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception – {0} – {1} – {2}" , "Sharepoint Application Name" , Ex.Message , Ex.StackTrace);


Catch the errors!!!

Thursday, July 23, 2009

SharePoint Terminology and Concepts – Basics of SharePoint

Actually when I have started with SharePoint development, I have many basic questions, like why people are calling 12 folders as 12 Hive, what are content type and many more, so I thought to share with you some basic terminology, concepts and definitions for the same which are using in day to day life while working with SharePoint.

12 Hive- a folder used by SharePoint to share all files that are not stored in the Content and Configuration Database. The Location is LocalDrive:\Program Files\Common Files\Microsoft Shared\web server extensions\12. (Why this location? Since the SharePoint architecture is an extension of IIS, perhaps this is why these files are stored under web server extension.)

CAML - Collaborative Application Markup Language. It is an XML based language which is used to fetch data from SharePoint objects such as lists, document library.

Central Administration – is a special SharePoint website that allows users to perform administrative tasks for the farm. Site is Accessible via Start -->Administrative Tools.

Configuration Database - every SharePoint farm has a single farm wide configuration database that contains configuration data such as which Web Servers are associated with the farm and which users have admin privileges.

Content Database - Typically there is one content database per Web Application. It stores the data associated with that Web application including .aspx pages. As per Microsoft, it’s not feasible or good to write query against database through ADO .NET code or any other way. Only go through the SharePoint Object Model.

Content Type - a reusable type definition that defines the columns and behavior of an item in a list or document library. It can include a set of columns, event handlers, document templates and workflows.

Farm - a set of one or more computers that work together to provide WSS functionality to clients. A simple farm can be a single computer that hosts WSS and SQL. A more complex farm can consists of several front-end Web servers and a dedicated database server.

Feature - allow developers to define site elements and add them to a target site by simply activating the feature. Features can be packaged into solutions and very easy to deploy. They reside in a feature.xml file which uses CAML. Other files are also required such as elements.xml files which define the elements and make up a feature (list definitions, page templates, etc.)

IIS Website- Provides an entry point to IIS and listens for http requests .The default IIS website listens on port 80.

Item - a component of SharePoint site such as the entire farm, a Web Application, or a content database. It seems that an "Item" is defined to be whatever is returned by the -showtree option in the stsadm backup command.

Provisioning - provisioning simply means creating. So provisioning a site collection means creating a site collection.

Site - A storage container for content (such as WebPages), that is always scoped within a site collection. Site content includes lists, documents, and libraries. A site is a foundation for web parts. Also called WSS Site.

Site Collection- a container for WSS Sites also called a WSS Site Collection. Under a web application, the way site collection and sites are organized affects the scope of administrative privileges, security boundaries, and backup and restore operations.

Site Column - a reusable column definition that can be used across multiple lists. A site column defines its name, field type. Default value, formatting and validations. It is then used in lists and document libraries. Later, if the site column definition changes, all lists that use it are also updated.

Site Definition- the top level component in WSS that aggregates smaller definitions to create a site template that can be used to provision sites. To provision a site, a site definition must define one or more configurations. It is site definition's configuration that is actually used to provision a site.

Solution - Solution can be easily deployed. They can contain features and other wss components. It is also known as WSS Solution or .wsp file.

Subsite - informal term that refers to a sub site.

SSP - Shared Service Provider. These are built into SharePoint and include things like Search or Excel Calculation Services.

STSADM - a command line utility, used to perform administrative tasks. STSADM allows users to create site collections, backup and restore operations and more.

Virtual Server-the old name for what is now called a Web Application.

 WebApplication- an IIS website that has been configured to run WSS Sites.(Not a virtual directory).IIS performs authentication , but the SharePoint Web Application performs the authorization.

Web- A top level site was originally called a Root Web.

WorkFlow - Windows Worfklow Foundation, used to attach business logic to list items and documents in a WSS Site. A task list and history can be associated with each workflow. If created using SharePoint Designer, WSS Workflows are difficult to deploy. For professionally developed projects a .NET Solution should be used instead.

WSS Object Model - The object model used to develop SharePoint Applications. The Object model programmatically exposes sites and site Collection. To enable intelligence in Visual Studio you need to copy wss.xsd from 12 hive TEMPLATES folder to c:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\.

To avoid using excessive amounts of memory, use need to call dispose for SPWeb and SPSite objects since they are unmanaged resources.

Monday, June 22, 2009

How to customize edit forms in SharePoint designer 2007

Hello Friends

v      Business Case:

Let’s say we have custom list and when any user enters a new item into list, every field must be editable, but when user edits any item, at that time some of fields should not be editable, they should come only for display purpose.

v      Possible Solution:

We can develop custom web part and write code to make some fields read only but we can easily achieve above functionality by just customizing edit forms into SharePoint designer.

v      Solution:

A very simple solution

1>     Open SharePoint Designer 2007

2>     Open your SharePoint site

3>     Open Custom list

4>     Select Editform.aspx and .right click on it same file

5>     Click on “New from Existing Page” Option value, it will create one new custom ASPX page for us from existing one.

6>     Delete one web part which is already there into page and add click on Insert SharePoint Controls  -> Custom List Form.

7>     Select Appropriate List, it’s content type and Type of Form to create as per below image.

8>     Click Ok button. It will automatically add one new Data Form Web part with all list fields in edit mode.

9>     Now you can change this form as per your needs and requirements. Like if you do not want some of fields then you can delete those fields from current page. In my requirement I have to make “EmployeeID” as read only field means user can see the field but they can’t change the field values..

10>  Select EmployeeID Field from user interface. Click on “tag Properties”, there you can see “Control Mode” as Edit.

11>  when you click on ControlMode option, you can see available values that are Invalid, Display, Edit and New. Select “Display” as option value for displays purpose.

12>  Save form under your current site name -> Lists->List Name and give file name with .aspx extension.

13> Select List -> Right Click List Properties and Go to Supporting Files and In Edit Item Form Properties, Browse to Your newly created Form and click on apply and Save the site.

14>  Go to your SharePoint site .Select list and click on edit item, here in edit page you can see the result.

In these ways from SharePoint designer, we can make some of the fields as read only and editable also, I think, SharePoint designer is very powerful tool; just we need to find in which way we can take advantage of designer functionality!!

How to access fields of List Item in ItemAdding and ItemUpdating event handlers into SharePoint

When we need to validate something or put restriction before adding or modifying data, at that time we need to use ItemAdding or ItemUpdating Event Handler, here I’ll demonstrate how to access fields of List into event handlers.


As per my requirements, I don’t want to add duplicate Name into List. For this I need to check that condition before I add and update item to List, I need to use “ItemAdding” and “ItemUpdating” event handlers

public override void ItemAdding(SPItemEventProperties properties)
string strName = string.Empty;

foreach (DictionaryEntry entry in properties.AfterProperties)
if (entry.Key.Equals("Name"))
strName = entry.Value.ToString();

SPList list = properties.OpenWeb().Lists[properties.ListId];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='" + list.Fields["Name"].InternalName + "' /><Value Type='Text'>" + strName + "</Value></Eq></Where>";
if (list.GetItems(query).Count > 0)
properties.Cancel = true;
properties.ErrorMessage ="Name already exists!";
public override void ItemUpdating(SPItemEventProperties properties)
string strName = string.Empty;
foreach (DictionaryEntry entry in properties.AfterProperties)
if (entry.Key.Equals("Name"))
strName = entry.Value.ToString();
SPList list = properties.OpenWeb().Lists[properties.ListId];
SPQuery query = new SPQuery();
query.Query=  "<Where><And><Neq><FieldRef Name='"+ list.Fields["ID"].InternalName+ "' /><Value Type='Number'>"+ properties.ListItemId+  "</Value></Neq><Eq><FieldRef Name='"+ list.Fields["Name"].InternalName+ "' /><Value Type='Text'>"+ strName+ "</Value></Eq></And></Where>" ;
if (list.GetItems(query).Count > 0)
properties.ErrorMessage ="Name already exists!";

Wednesday, June 17, 2009

How to add/update SharePoint person/group field from Object model

While adding/updating the person/group field, we need to take care, because it’s required to be in specific format like value must be ID;#Name when assigning value.

Example code:
using (SPSite site = SPContext.Current.Site)
using (SPWeb web = site.OpenWeb())

web.AllowUnsafeUpdates = true;
string loginName = "domainname\\username";
SPUser theUser = web.SiteUsers[loginName];
SPList theList = (SPList)web.Lists["firstcustomlist"];
SPListItem theItem = theList.GetItemById(1);

theItem["usercol"] = theUser.ID.ToString() + ";#" + theUser.Name;
catch (Exception ex)
string msg = ex.Message;

How to display users to SharePoint People Picker control and get data from SharePoint People Picker control

In below example, I’ll demonstrate how to display users to people picker web control and get data from the same control. I have field called “Staff Assigned” and its data type is People/Group.

Below code will tell us how we can take data from that people/Group field and display to people picker SharePoint web control and also get data from people picker and give back to people/Group field from object model programmatically.

//Display users from people/Group field to People Picker Control

if (itmAudit["Staff Assigned"] != null)
char[] to_splitter = { ';' };
string to_list = itmAudit["Staff Assigned"].ToString(); // Reads value stored in SPList. (i.e., "Domain\User1; Domain\User2")
string[] arr = to_list.Split(to_splitter);
string user = string.Empty;
System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
for (int i = 1; i < arr.Length; i++)
if ((i % 2) != 0)
user = arr[i].Substring(arr[i].IndexOf("#") + 1);
PickerEntity entity = new PickerEntity();
entity.Key = user;
entity = userPicker.ValidateEntity(entity);


//Save users to people/Group field from People Picker Control

SPFieldUserValueCollection values = new SPFieldUserValueCollection();
foreach (PickerEntity entity in userPicker.ResolvedEntities)
SPFieldUserValue fuv = new SPFieldUserValue(SPContext.Current.Web, Convert.ToInt16(entity.EntityData[PeopleEditorEntityDataKeys.UserId]), entity.Description);


itmAudit["Staff Assigned"] = values;

How to get Versioned Multi Line Text as Plain Text of Multiline Text (Append Text/Version Applies) Field in SharePoint


In custom list we have field “Comments” and it’s type is Multi Line Text with Version and selected ”Allow append text” as option, now if we want to check all Versioned Comments /History of comments with entered text, date and time and person name then if we try to access it’s field value programmatically by list item then it will always returns latest version.

Below code will explain and demonstrate how we can take version of multiline text values with username, date and time.
public static string GetVersionedMultiLineTextAsPlainText(SPListItem item, string key)


StringBuilder sb = new StringBuilder();

foreach (SPListItemVersion version in item.Web.Lists[item.ParentList.ID].Items[item.UniqueId].Versions)


SPFieldMultiLineText field = version.Fields[key] as SPFieldMultiLineText;

if (field != null)


string comment = field.GetFieldValueAsText(version[key]);

if (comment != null && comment.Trim() != string.Empty)



sb.Append(version.CreatedBy.User.Name).Append(" (");

sb.Append(version.Created.ToString("MM/dd/yyyy hh:mm tt"));

sb.Append(") ");





return sb.ToString();


Tuesday, June 16, 2009

Monday, June 15, 2009

Visual Studio 2005/2008 Sharepoint Workflow with Active Directory

Hello Friends

Business Case:

In Project, Requirement is like develop one workflow steps like

 1>     Create task and Assigned To is its manager which is decided by Active Directory

2>     Tasks are created like Originator à Project Manager à Director àDeputy à Superintendent. (Means we have to go to that level until whose manager does not exit.)

3>     For every user we have to create one task .If it is approved or deferred we have to send mail. If it is approved we have to send mail to person who has created task for the manager and create a new task for next level.

4>     Now if a person does not look at that task up to some duration we have to send email to person for overdue task and extend its due date for one day.

5>     If person deferred task workflow must be terminated. And email also sends for task is deferred or cancelled.

6>     Main requirement is that we have to search for manager from Active Directory.


Develop a Sequential workflow.

Let us go into detail

1>     Create new project Project Type Sharepointà Sequential Workflow.

2>     Now Select activity that is “TaskCreated”.

3>     Then we have to add one while activity where we put one condition check that manager name is empty or not and if not then workflow must be stopped.

4>     Now there is one limitation of while activity is we add only one activity under while activity so I add one sequence activity and in that I add conditionactivitygroup there.

5>     In that I add one activity which is “CreateTask” Activity .Then on I add “OntaskCreated” Activity.

6>     Then I have to do like when task status changed from not started to Completed or Deferred we have to wait So I add one condition activity group which has condition like up to taskiscompleted == true.

7>     In group of activities I took 2 Sequence Activity. First Sequence activity is as under

 8>     And another one is as follows.

9>     In last once again we have to write one code activity which takes managername of current user.

10>  Workflow is completed

11>  How we can take manager name from Active Directory.

For that we have to use one directory Add reference

using System.DirectoryServices;

and also for regx you have to use

using System.Text.RegularExpressions;

        private string getManagersName(string employeesName)


            string managersName = string.Empty;

            // Strip off the domain reference: eg: somecompany\\someusername. "somecompany\\" is the domain reference

            string cleanUserName = employeesName.Substring(employeesName.LastIndexOf('\\') + 1);

            // Setting the Active Directory folder to the root foler

            DirectoryEntry adFolderObject = new DirectoryEntry();

            // Creating the AD Searcher Object

            DirectorySearcher adSearcherObject = new DirectorySearcher(adFolderObject);

            // Setting the Search Scope to the AD Root tree and the subtree

            adSearcherObject.SearchScope = SearchScope.Subtree;

            // Get the UserName of the person who uploaded the document from the Document Library

            employeesName = workflowProperties.Item.GetFormattedValue("Created By");

             cleanUserName = Regex.Replace(employeesName, @"<(.|\n)*?>", string.Empty);

            // Set the Active Directory Search Filter to the, now stripped, username

            adSearcherObject.Filter = "(CN=" + cleanUserName + ")";

            // Execute the Active Directory Search

            SearchResult adObject = adSearcherObject.FindOne();

            // The Active Directory Search will return several properties for the Manager Object.

            // Store them in an array

            string[] properties;

            // Ensure that the user has a value in the Manager field

            if (adObject.Properties["Manager"].Count > 0)


                // The properties are "," delimited, so we will split the properties on that character

                properties = adObject.Properties["Manager"][0].ToString().Split(',');

                // The Manager Name field starts with "CN=...", so stripping that off leaves us with the

                // Managers Name

                managersName = properties[0].Substring(3);

                // Get the Domain of the Users Active Directory Root

                string domain = adFolderObject.Name.Substring(3);

                // Convert the manager string to a SPU User Field

                managersName = workflowProperties.Web.AllUsers[domain + "\\" + managersName].ToString();


            // return the managers name or an empty string, if there is no manager

            return managersName;


12>  Second thing When you have list field type as “People Or Group” if you access fieldvalue and you want that thing display as “domainname\username”.You must have to use

employeesName = employeesName.Substring(employeesName.IndexOf(@"\") + 1);

13>  When you want to access some users which are in list and you want to use that name in task assigned list so you have to do one change and that is go to that edit that column and make Show Field as “Account”.

Now I will give you concept wise description.


The ConditionedActivityGroup activity is a CompositeActivity, meaning the ConditionedActivityGroup activity is group of other activities. The ConditionedActivityGroup activity runs and re-executes child activities based on the evaluation of their when conditions. All rules are evaluated whenever required based on their data and state change dependencies. All of activities until an until condition is true of ConditionActivityGroup.

UntilCondition = this._IsTaskCompleted == True

SequenceActivity :

The SequenceActivity is a CompositeActivity, meaning the SequenceActivity can contain other activities.

The SequenceActivity class coordinates a set of child activities in an ordered manner, one at a time. The SequenceActivity is completed when the final child activity is finished .There is one when condition is attached with Sequence Activity. If we do not specify that condition then it executes all activities under Sequence activity one at time but if we wish to executes all activities must run under some condition we can specify that thing under when condition and when it is true then and only then all activities run.

First Sequence Activity When Condition : None

Second Sequence Activity When Condition : this._IsTaskCreated == True && this._IsTaskCompleted != True


The Delay activity causes the containing branch of the workflow to wait for a specified amount of time

I need that otherwise workflow goes into infinite loop I have to tell workflow to wait for 2 minutes. Then check code condition for due date.

Web Part error “Custom Web part properties does not show up”

Today I was struggling with custom web part properties error; it was giving me error “Custom Webpart properties do not show up”.

The error solution was that if you inherit your web part from System.Web.UI.WebControls.WebParts.WebPart then you have to insert these lines for custom web part properties

[Personalizable(PersonalizationScope.Shared), WebBrowsable(true), SPWebCategoryName("MediaServerURL"),Category("Miscellaneous")].
And when you inherit your web part from this namespace Microsoft.SharePoint.WebPartPages.WebPart then you have to insert below lines for custom web part properties

false), Category("Miscellaneous"), DefaultValue(defaultAssociatedListID), WebPartStorage(Storage.Shared), FriendlyName("AssociatedListID"), Description("AssociatedListID Property")]

I hope this will help to someone.

Sunday, June 14, 2009

How site Templates can be moved to Central Site Template Gallery

Hello Friends,

Business Case:

 In our organizations there are more than one Intranet Portals. Different web application like one is parent and web application for each department – its sub department, each for user required solutions (we called as application). Now main requirement is every portal has look wise same. Like every intranet portal must have some of lists like “Department, Divisions, Menus, etc. “. Some of intranet portal does not have Quick Launch and while some have. Welcome page must be same. Site themes some of font styles, home logo, banners must be same.


Problem is for every application we have to manually create lists and makes entry as well as we have to change quick launch and also some other layouts modification we have to do manually from SharePoint Designer. Really a very tedious work for developers.

Existing Scenario:

Created web application from central Admin by selecting one of template from out of box and did manually changes. Same thing do again and again!! Wastage of time.

Possible Scenario:

So we decided that we have to create our own site Template and apply that site template to newly created web application depends on requirement whether we require new application with quick launch or not.

 Possible Solutions:

We have two options to create custom template 1) Site Definition 2) Site Template

Let me explain you when we have to use SiteTemplate & SiteDefinition and

When we discuss this topic how can we forget about Ghosting & UnGhosting and main topic is when we use siteTemplate how we can add that thing to CentralAdmin.

What is Ghosting-Unghosting & Difference between Ghosting & Unghosting:

When you create a new site, SharePoint doesn't have same pages for different sites— default.aspx and so on—into a new database table or directory. These files exist once and only once on each of the front end Web servers. Instead, SharePoint creates a reference to those files in the database tables that define the new site, a process called "ghosting." The outcome is that the site appears to have its own unique pages, but the pages are actually shared across all sites that use the same definition. So ghosting is jargon which is used in SharePoint 2003 and same concept but in SharePoint 2007 it is known by new word and that is “Uncustomized”.

This has two distinct advantages over copying the files to each site individually when the site is created. It saves space. Say example, If you have a hundreds sites, rather than having a hundreds copies of same file you still have only one copy. It improves performance. The server needs to cache only one copy from the file system, which can improve performance by freeing cache memory for other things. Loads the file from the Web server's local file system improves performance by eliminating the overhead of the database call and the network traffic to the database. One interesting benefit of this approach is that when you make a change to one file on the file system, that change takes effect across all the sites that have been created. There are some limitations like SharePoint can not ghost every page so we use concept Unghosting. Unghosting means when we customize page whose customization stored in database it is known as “unghosting” in SharePoint 2003 and “customized” in SharePoint 2007. Unghosting lets users customize their own sites without impacting other users who might be using the same file. But unghosting also has a performance impact negatively. Normally there are some of Site templates are already available which are out of box to Site Templates Like “Team Site”, “Blank Site”, Meeting workspace” There is very common and frequently requirement for customizing portal sites and other SharePoint sites. There are normally two approaches uses for customizing sites they are: 1> Site Definition 2> Site Templates Let I will give you description of every approach and also let you know when we have to use both.

 When to use Site Definition:

 A site definition defines a unique type of SharePoint site.When we use site definitions we require access to the file systems of the Web server. When we use site definition we will edit the Schema files directly. In spite of deploying a site definition requires more tedious and manually work, site definitions typically perform better when cached on the file system instead of in the database. We have finer level of customization by directly editing all the schema files and not depending on the existing site definition as a site template does. To introduce new file types, view styles, and drop-down edit menus, just need to edit the schema files that make up the site definition. Custom Site Definition also has capability of versioning. Using custom site definitions excludes your sites from potential upgrade issues. However, there is no easy way to modify site definitions once they are deployed. You can only add new types, view types to the site definition once it is deployed. 

 When to Use Site Templates Site templates, compared to site definitions, are easy to create and deploy. Because customization can be done through SharePoint Designer 2007 or user interface. Modification is really easy as compared to Site Definition and it does not effect to existing sites created by that templates. Deployment is simple because template data is stored centrally in the configuration database. Because it is slow to store templates in and retrieve them from the database, site templates can result in slower performance. Templates in the database are compiled and executed every time a page is rendered. Windows SharePoint Services does some performance optimization whereby it stores templates on the local Web server and a copy (or “ghost”) of the page in the configuration database. Rendering pages from the database will result in an initial performance penalty. If the site definition does not exist on the server, the site template fails.

 Solutions Offered Finally:

Typically, because of these issues, site templates are not as efficient as site definitions in a large-scale environment. It is used when we have to go for very small changes to like changes in logo, small things. Site templates are stored in the Site Template Gallery of the top-level site in a site collection, where they become available for subsite creation on all sites in the site collection.

How site Templates can be moved to Central Site Template Gallery?

Here it is: When we create some Site templates we can use it any site and now if you want to display that site template in Central Admin and apply it to entire web application and globally Available …we have to use stsadm command line tool and use addtemplate command. In my project we want one siteTemplate which does not have Quick Launch and some lists are common like Office, Division and Department. So first we think that we have to create site definition because we want that thing as globally available to Central Admin. But we are unaware of functionality of stsadm addtemplate command. Then once we know about that first I updated default.master from SharePoint Designer. In that site I added 3 lists Office, Division and Department. Then from siteSettings we save that template as Site Template to Local drive.

Then use command

stsadm –o addtemplate -filename “C:\CustomTemplate.stp” –title “A Template without Quick Launch” Description of the command is as follows:

 Command Syntax like: stsadm -o addtemplate -filename -title



FilenameA valid file name, such as “C:\Templates\SampleTemplate.stp”YesFile name of the template that you are adding
TitleA valid title of a template, such as “Sample Template”YesTitle of the template that you are adding
descriptionA valid description of the template, such as “This is a sample template”NoDescription of the template that you are adding


Stsdm –o addtemplate –filename  “Path of file siteTemplatefile” –title  “Title of SiteTemplate when it displays at SiteTemplate Tag”

Don’t forget to do iisreset and now it is available to central admin as global template.

  • Second way to do this thing is:

In code, use AddCustomGlobalWebTemplate method of the SPGlobalAdmin class to add a site template to the gallery.

Friday, June 12, 2009

How to set version history of multiline into SharePoint list

Hello friends

When we need to maintain comments history in sharepoint list for every item , like comment description, User name and date and time of comments entered, what we need to do is , add one custom field in your list as “Comments “(or you can use any User Friendly field Name) and make its type as “Multi Line of Text” and make sure you select “Append changes to Existing Text”

List its versioning Settings must be set.

Now this will show you result of that Comments

So here may be same user or different user can add their comments and it display like User Name, Date-time of entered comment, and Comment Description in the same list item.

Tuesday, June 9, 2009

One of more field types are not installed properly in CAML Query

Hello Friends,
I got error "One of more field types are not installed properly" .
What does this mean?Let me first explain basic concept which is related to this error and you will find solution.

Whenever creating any column for list, SharePoint creates three names for it.
  1. External name /Display Name to display in views, forms
  2. Internal name we use in CAMP Query, Assign Values
  3. Static Name : Name which is used by field type.
If you are creating field from code behind then you can assign internal name as per your choice, but when doing it through SharePoint interfface, it gives you option to enter display name, and it creates internal name by itself. When internal name is defined, if you have any of the non alphabet as part of name SharePoint converts them to special hex codes.
For e.g. trying to create field “Emp Name” gives internal name as “Emp_x0020_Name”
You can think like why this description is needed!!!But for the error like "One of more field types are not installed properly" in their applications.“You must understand this concept vey well. You must have clear picture of that.
So now for that error there is no problem with creating list and their fields.
The problem is simple:
CAML Query always uses Internal Name.
CAML Query uses Internal name not display name.If you have a field called "Program ID" (for example), in CAML you should refer to it as “Program _x0020_ID", because the internal name is encoded to avoid special characters.

Also, the internal name may be totally different from the display name - this will happen if you created a field and then renamed it.
Let’s Say we create a custom List name as “Employee” . Now Title field is already available.
Now I want to rename “Title” with “EmployeeID” But when I rename it ,it only and only changes display name but its internal name does not change. And Internal name is always created when we create field first time. We can not change internalname afterwards. So the internal name remains the same as the old name, but the display name changed. You can change the display name as many times as you want, but can never change the internal name once column is created.
So, how to know about the internal name for field?
Let me clear entire picture by elaborate an example. Every List has Field name as “Created By” field which is having internal name “Author” and Display Name as “Created By”.
If you want to know internal name of particular field how you can indentify .Go to ListàList Settingsà Click On Column (Created By) à so you have Edit Column Page. On that page you can see Column Name Textbox has its display name as “Created By”. Now Look at Addressbar It looks like this.
Internal Name of any field is identified by Field=InernalNanme. So Internal Name is for “Created By” is “Author”.
So Now If you wish some easier way to write CAML and do not want to find internal name by checking “Field” from address bar use Some CAML Query Builder.
I provide One table so you can convert Hex code to Character like Program _x0020_ID as so we have x0020=”” See last Row of this table “Program ID”


Internal Hex Code



























































Disha Shah