The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

  • Advertisements

Archive for the ‘Articles’ Category

Moss case studies and Internet sites

Posted by Clayton James on November 29, 2007

More SharePoint 2007 case studies and Internet sites.



Posted in Articles, MOSS 2007 | Leave a Comment »

MOSS, AJAX and the AutoCompleteExtender

Posted by Clayton James on July 8, 2007

This article will look at utilising ASP.Net 2.0 AJAX inside WSS 3.0. This article is also based off some great work completed by Todd Bleeker in his book Developers Guide To Windows SharePoint Services 3.0.

To complete the code associated with this article you will need to install ASP.Net 2.0 AJAX Extensions and the ASP.Net 2.0 AJAX Control Toolkit as we will be utilising AJAX Extensions, namely the AutoCompleteExtender control.

The first thing you need to do is make your WSS site AJAX ready. This blog article from the SharePoint team takes you through the steps in completing this and also has a nice little web part example to test and make sure everything is working as it should be.

Ok, what we are going to demonstrate is creating an AutoComplete Web Part that provides users with the ability to filter a drop down list as they type in a text box. See image below. This will be a two step process, firstly creating a web service that is the data source for the drop down list, and secondly creating the AutoComplete Web Part. I must also point out that there is no difference between creating this Web Part in WSS 3.0 or any standard ASP.Net 2.0 application (which is what WSS is J).

Web Service

  1. Open VS.Net and choose ASP.Net AJAX Enabled Web Site template (if you don’t see this option then you need to install ASP.Net 2.0 AJAX)
  2. Ensure location is HTTP and enter a URL like http://localhost/WebServices.
  3. In Solution Explorer, right click the project name and add a new item. Choose Web Service from the templates window.
  4. Enter SimpleWebService for the name and uncheck the Select code in separate file checkbox.
  5. Decorate the class with the ScriptService to enable AJAX calls.

    public class SimpleWebService : System.Web.Services.WebService

  6. Create a WebMethod that will return a list of employees. The WebMethod must conform to the precise interface expected by the AutoComplete extender control which includes two arguments that must be named prefixText and count. The prefixText argument contains the letters typed by the end user and the count contains the maximum number of items returned.



    public System.Collections.Generic.List<string> GetEmployees(string prefixText, int count)


                    string[] employees = new string[]{

    ‚ÄúAdam Wells‚ÄĚ,

    ‚ÄúJames MacGuire‚ÄĚ,

    ‚ÄúJeff Phillps‚ÄĚ,

    ‚ÄúJemma Knowles‚ÄĚ,

    ‚ÄúMary Jullop‚ÄĚ,

    ‚ÄúMark Dent‚ÄĚ};

    System.Collections.Generic.List<string> employeeList = new System.Collections.Generic.List<string>();

    Int i = 0;

    foreach(string employee in employees)


                    //check if max number of employees has been reached

                    if(i == count)




    else if(employee.ToLower().StartsWith(preficText.ToLower()))






    return employeeList;


    This WebMethod returns a string array containing the first and last name for employees. This example could easily be altered to return a result from a database.

  7. This ends the Web Service/WebMethod necessary for the AutoCompleteExtender control.

Ok, now for the Web Part.

  1. Open VS.Net and create a new Class Library project. Enter AJAXStyleWebParts for the name.
  2. Add a reference to the ASP.Net AJAX assembly (Microsoft.Web.Extension.dll), and to the toolkit assembly AjaxControlToolKit (the extender controls are not found in the core ASP.Net AJAX assembly and you will need to build the ToolKit solution that you downloaded previously at the beginning of the article).
  3. Add a new class called AutoCompleteWebPart : System.Web.UI.WebControls.WebParts.WebPart (and inherit WebPart class)
  4. Add declarations to the top of the class:using

    using System.Web;

    using System.Web.UI.WebControls;
    using AjaxControlToolkit;

  5. Override the CreateChildControls method
  6. protected override void CreateChildControls()


                //establish a path to the web service

    ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† string webServicePath = ‚Äúhttp://localhost/WebServices/SimpleWebService.asmx‚ÄĚ;¬†



    //TextBox label

    Literal textboxLabel = new Literal();

    textboxLabel.Text = ‚Äú”Type the name of a Employee: “;



    //TextBox to extend with the AutoComplete AJAX behaviour. Note: this is a normal asp textbox

    TextBox textbox = new TextBox();

    textbox.Attributes.Add(‚Äúid‚ÄĚ, ‚ÄúSelectEmployeeTextBox‚ÄĚ);



    //autocomplete AJAX behaviour

    AutoCompleteExtender autoComplete = new AutoCompleteExtender();

    autoComplete.MinimumPrefixLength = 1;

    autoComplete.ServicePath = webServicePath;

    autoComplete.ServiceMethod = ‚ÄúGetEmployees‚ÄĚ;

    autoComplete.TargetControlID = ‚ÄúSelectEmployeeTextBox‚ÄĚ;



    catch(Exception ex)


                    Literal errMsg = new Literal();

                    errMsg.Text = ex.Message;




  7. This ends our AutoComplete Web Part. Now all we have to do deploy to the web applications bin directory or GAC, add a safe control entry, recycle the app pool, add the Web Part to the gallery and then add to your WSS page.
  8. Type the letters “mar” in the textbox to see the Web Part in action.
  9. So, now you have AJAX’ed your WSS site, created a Web Part and implemented the AutoCompleteExtender control which I think provides great functionality for any WSS site.

Posted in .NET 2.0, Articles, WSS 3.0 | 26 Comments »

Regular Expression Validation Custom Field Type

Posted by Clayton James on May 15, 2007

I have been reading Todd Bleekers book Developers Guide To Windows SharePoint Services 3.0 and came across a great implementation in creating a custom field¬†type in WSS 3.0. This custom field type is a Regular Expression Validation Custom Field Type. I love this implementation as it can be used for many situations…anywhere you want to validate input using¬†regular expressions.

  • Emails

  • Telephone numbers

  • Address

  • Numbers only

  • Letters only

  • Alphanumeric only

If you are after a regular expression to validate input then this is one of the best sites to use.

Here are a couple of screen shots that displays the objective.

A Custom Field Type is a class that is complied into an assembly, so the first thing to do is open VS.NET 2005 and create a new Class Library project.

  • Provide a¬†meaningful project¬†name

  • You need to add an assembly reference to Windows SharePoint Services¬†in the .Net project.

  • Rename the default class Class1.cs to RegExTextField.cs. (VS.NET will refactor the project to update the related references to the new class name)

  • Add two directives to the top of the class.

    • using Microsoft.SharePoint

    • using System.Text.RegularExpressions

  • You need to now inherit functionality so it behaves like a CFT. There are many different CFT classes you can inherit from to get different behaviour, but we want to inherit the SPFiledText as this most resembles our CFT. So the declaration will look like the following

    • public class RegExTextField : SPFieldText

  • WSS v3 will call into one of two constructors so the class must implement both of them even though they don’t implement any code.

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

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

  • The GetValidatedString method converts the field type value into a validated serialised string. We can use this method to create our own custom validation from the value entered. Insert this after the second constructor.

    public override string GetValidatedString(object value)
        string textValue = value.ToString();

    //Only compare RegEx if a value is present
    if (textValue.Length > 0)
        //setup regex based on custom property
¬†¬†¬†¬†¬†¬†¬† Regex reg = new Regex(GetCustomProperty(“RegularExpression”).ToString(), RegexOptions.IgnoreCase);

        //if the value entered does not match
        if (!reg.IsMatch(textValue))
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† throw new SPFieldValidationException(GetCustomProperty(“ExceptionMessage”).ToString());
            return textValue;
        return textValue;

  • Sign the assembly so it can be deployed to the GAC. You can sign the assembly by navigating to the Class Library project properties and click the Signing tab. Build the project to produce the assembly and deploy to the GAC.

Now you need to define what elements you want displayed when the CFT is used in the Create Column and Additional Columns Settings.

  • In the same Class Library project choose Add √†New Item and select XML File.
  • In the Name field type fldtypes_RegExTextField.xml. (The name of the file is important as CFTs must begin with fldtypes)
  • Add the following code to your .xml file

    <?xml version=”1.0″ encoding=”utf-8″ ?>
    ¬†¬†¬†¬†¬†¬†¬†¬†<Field Name=”TypeName”>RegExTextField</Field>
    ¬†¬†¬†¬†¬†¬†¬†¬†<Field Name=”ParentType”>Text</Field>
    ¬†¬†¬†¬†¬†¬†¬†¬†<Field Name=”TypeDisplayName”>
                Single line of text (with RegEx validation)
    ¬†¬†¬†¬†¬†¬†¬†¬†<Field Name=”FieldTypeClass”>
                CustomFieldTypes.RegExValidation, Version=,
                Culture=neutral, PublicKeyToken=d7f772d26282eb60
    ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†<Field Name=”RegularExpression” DisplayName=”Regular Expression” MaxLength=”255″ DisplaySize=”35″ Type=”Text”>
    ¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†<Field Name=”ExceptionMessage” DisplayName=”Exception Message” MaxLength=”255″ DisplaySize=”35″ Type=”Text”>

    • The FieldType elements define the attributes associated with the CFT when it appears in the Name and Type section of the Create Column page.
    • The PropertySchema elements define the attributes associated when it appears in the Additional Column Settings (after you select the CFT radio button)

  • CFT have two scopes, Farm or List.

    • Farm: fldtypes*.xml files reside in the ..\12\Template\XML folder.
    • List: The schema.xml file that defines a list template can include CFTs.
  • Because this CFT will be useful across the farm we will copy it to the ..\12\Template\XML folder In Windows Explorer copy the fldtypes_RegExTextField.xml to ..\12\Template\XML.
  • Now all you have to do is perform an application pool recycle, then go to any WSS 3.0 list and add a new column and you will see your CFT.

Now you can use your new WSS 3.0 RegEx Validation CFT in many situations.

Posted in Articles, WSS 3.0 | 48 Comments »

MOSS 2007 Setup Accounts

Posted by Clayton James on April 23, 2007

Installing MOSS 2007 in a farm environment requires a few dedicated accounts and can be quite a confusing process. I came across a couple of great resources so I thought I would save you the heart ache and post them here. 

This information was found¬†on TechNet and in Bill English’s book Microsoft Office SharePoint Server 2007 Administrator’s Companion

It is strongly recommended that you use a dedicated account to log in and install Windows SharePoint Services and SharePoint Server 2007 servers. This account can also be used as the identity of the Central Administration site application pool, or it can be unique. By design, the Welcome menu displays “system account” if that account is used to log on to any application pool or Web site. This behavior continues even if the application pool identity is changed to the Network Service. This means your administrator account should not be used as an application pool identity or to install an SharePoint Server 2007 server.

Account Purpose Scope Used By Needed Requirements
Setup User User account that is used to run setup on each server. Farm Person installing Setup Member of the administrator group on each Web front-end (WFE) server and application server computer in the farm. Member of the following SQL Server groups with SQL Security administrator and database creator rights on SQL servers.
SQL Server Service This is the security context used By Central Administration for creating databases and other SQL configurations. Farm MSSQLSERVER, SQLSERVERAGENT Setup Member of the administrators group on each server on which setup runs, administrators group on each SQL Server computer, database system administrator, and member of the SQL security administrator and database creator SQL Server groups.
Server Farm This account is also referred to as the database access account. Farm Central administration site application pool identity Setup Member of administrators group on each WFE server and application server computer in the farm with SQL security administrator and database creator rights on SQL Servers. Database Owner (DBO) for all databases and additional permissions on WFE server and application server computers are automatically configured for this account when SharePoint is installed.
SSP App Pool App SSP App Pool Identity SSP Creation No configuration is necessary. The following permissions are automatically configured for this account when SharePoint is installed: DBO for the Share Service Provider (SSP) content database, read/write permissions for the SSP content database, read/write permissions for content databases for Web applications that are associated with the SSP, read permissions for the configuration database, read permissions for the central administration content database, and additional permissions on WFE server and application server computers
SSP Service Account Used to run timer jobs and for interserver communications. Farm SSP Timer service; SSP Web services SSP Creation Same as SSP App Pool Account
Windows SharePoint Services Search Used as the service account for the Windows SharePoint Services Search service. There is only one instance of this service, and it is used by all SSPs. Farm Windows SharePoint Services 3.0 Search service SSP Creation Must be a domain account, but must not be a member of the farm administrators group. Permissions automatically configured for this account when SharePoint is installed include the following: read/write permissions for content databases for Web applications, read permissions for the configuration database, and read/write permissions for the Windows SharePoint Services Search database
Search Default Content Access Account The default account used by a specific SSP to crawl content. It is used when an account is not specified for a content source. App Windows SharePoint Services 3.0 Search service SSP Creation Must be a domain account, but must not be a member of the farm administrators group. It requires read access to external or secure content sources that you want to crawl using this account. Additional permissions for this account are automatically configured when SharePoint is installed.
Search Specific Content Access Account This is an optional account that is configured to replace the default content access account to crawl a specific content source. Rule Windows SharePoint Services 3.0 Search service Create a new crawl rule Read access to external or secure content sources that this account is configured to access.
User Profile and Properties Content Access Account Account used to connect to a directory service, such as Active Directory, a Lightweight Directory Access Protocol (LDAP) directory, Business Data Catalog (BDC) application, or other directory source and used to import profile data from a directory service. Note: If no account is specified, the Search Default Content Access account is used. If the Search Default Content Access account does not have read access to the directory or directories that you want to import data from, you will need to specify a different account. You should plan for one account per directory connection. App Profile Import SSP Creation Read access to the directory service. For an Active Directory service connection that enables Server Side Incremental, the account must have the Replicate Changes permissions for Active Directory directory services provided by Windows 2000 Server. This permission is not required for Windows 2003 Active Directory. Manage user profiles right. View rights on entities used in Business Data Catalog import connections.
Excel Services Unattended Service Account Excel Calculation Services uses this account to connect to data sources that require user name and password strings for authentication. The SSP App Pool account is used if none is specified. For security, plan to use a low-privileged account that does not have the database privileges of the SSP App Pool Account. App Excel Services Service SSP Creation Read/write access to the Excel data sources.
App Pool Identity Used to access content databases associated with the Web application. Plan one for each application pool. App Web Applications App Pool Creation No configuration is necessary. SQL Server privileges that are automatically assigned to this account are member of Database Owners Group for content databases associated with the Web application, read/write access to the associated SSP database only, and read permission for the configuration database. Additional privileges for this account on WFE servers and application servers are automatically configured by SharePoint.

Posted in Articles, MOSS 2007, Office 12 | 29 Comments »

Connect Virtual PC to Internet

Posted by Clayton James on February 2, 2007

¬†I have been using VPC for a few years now and I am still learning lots about using it. After upgrading to Vista I was unable to connect my VPC images¬†to the Internet to activate the OS and download system updates. I was scratching my head changing my VM¬†network adapter settings to¬†Shared Networking (NAT) or to¬†my wireless adapter but no matter what I did I couldn’t get an Internet connectivity from my VPC.

So I went to the person I always go to when I am stuck (this is the person after google) Mr Mark Daunt. He solved it in¬†about a¬†minute asking me if I have installed the Virtual Machine Network Service on my wireless adapter….the what???

So he showed me where to install it and wholla…I could connect ūüôā

My LAN adapter had the Virtual Machine Network Service¬†installed but my wireless adapter didn’t.

1/ Navigate to your physical network adapter that you want your VPC to use and click the Install button

2/ Highlight Service and click Add

3/ If you don’t see the Virtual ¬†Machine Network Service click¬†Have Disk button¬†(mine displays as I had already added it).

4/ Navigate to the following directory: C:\Program Files\Microsoft Virtual PC\Utility\VMNetSrv and select the VMNetSrv.inf file and Ok your way back out.

5/  This should install the service and you should now see the service in your connection properties

6/ In your VPC make sure you set your network adapter to the adapter that you just installed the Virtual  Machine Network Service

¬†7/ Internet connection from VPC¬†ūüôā

Here is a good blog post for a couple of other issues¬†if Virtual Machine Network Service is installed but you still can’t get network connectivity.

Another good article by Microsoft explaining the virtual machine network settings.

Posted in Articles, Virtualisation | 181 Comments »