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

  • Past Post

  • Vistor Locations

  • Advertisements

Archive for the ‘WSS 3.0’ Category

Security Trim "View All Site Content"

Posted by Clayton James on July 28, 2009

I have been asked this a few times. How can I remove the View All Site Content link for certain users?

The View All Site Content link can be a great navigational link or a problematic link that confuses end users.

The default security setting for this SPLinkButton is set to be displayed to everyone…and when I say everyone I mean everyone…viewers and even anonymous users. This is found in the master page in your site.

  1. Open up the master page in SharePoint designer
  2. Place the page into split view
  3. Click the View All Site Content link and in you code window you should see the following

<Sharepoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ViewFormPages”>
        <div class=”ms-quicklaunchheader”><SharePoint:SPLinkButton id=”idNavLinkViewAll” runat=”server” NavigateUrl=”~site/_layouts/viewlsts.aspx” Text=”<%$Resources:wss,quiklnch_allcontent%>” AccessKey=”<%$Resources:wss,quiklnch_allcontent_AK%>”/></div>


Thankfully we can easily upgrade the security to different security level. For example, if we change the PermissionsString=”ManageWeb” then only users who have this permission level (site admins) will see the View All Site Content link.

<Sharepoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ManageWeb”>
        <div class=”ms-quicklaunchheader”><SharePoint:SPLinkButton id=”idNavLinkViewAll” runat=”server” NavigateUrl=”~site/_layouts/viewlsts.aspx” Text=”<%$Resources:wss,quiklnch_allcontent%>” AccessKey=”<%$Resources:wss,quiklnch_allcontent_AK%>”/></div>


There are a number of different permission levels that you can view here.

The SharePoint:SecurityTrimmedControl is a handy control that can be used in many locations. For example, wrap it around the Site Actions control for custom and you remove this control based on security.


Posted in WSS 3.0 | 19 Comments »

Add .Net User Controls to SharePoint

Posted by Clayton James on May 25, 2009

I have been developing inside SharePoint for a while now and while things are getting easier with tools I think this process for developing User Controls inside SharePoint gives me a lot of control.

  1. I have a Graphical User Interface
  2. I have a separate project to build and test outside of SharePoint
  3. I can easily update and view my project html and binary code

Currently this process doesn’t create me any SharePoint Solution files to deploy across environments. I think to achieve this I will need to create a VS 2008 SharePoint Project…but so far these projects seem to add weight and time that I don’t want at the moment…while I am developing.

  1. Create a VS2008 web project
  2. In IIS create an IIS Application under your SharePoint web site that has a path to your VS2008 web project created above. This helps for updating content
  3. In your VS2008 project create some user controls and test that they function
  4. In VS2008 project properties under the Build Events¬†tab point the Post Build events text box and add a copy statement to copy your .dlls and .pdbs to¬†your SharePoint web sites bin directory. This will deploy a new .dll every time you build your VS2008¬†project. I had problems when I put the VS2008 project .dll into the¬†GAC…it only worked when I put it into the SharePoint’s web sites bin directory
  5. Update your master page with CSS references if your VS2008 project contains a style sheet.
  6. In SPD in your Page Layout add a Register directive to register your user control
    “<%@ Register Src=”~/UI/UserControls/JobGoals.ascx” TagPrefix=”uc1″ TagName=”JobGoals” %>”
    Update the SharePoint web site web.config file
    ¬†¬†¬†¬†¬†¬†¬† <add¬†src=”~/UI/UserControls/MyAttributes.ascx”¬†tagPrefix=”uc1″ tagName=”MyAttributes”/>
    ¬†¬†¬†¬†¬†¬†¬† <add src=”~/UI/UserControls/JobGoals.ascx” tagPrefix=”uc1″ tagName=”JobGoals” />
  7. Add the User Control to the Page Layout
    <uc1:JobGoals ID=”JobGoals1″ runat=”server” />
  8. Update the SharePoinnt web sites web.config file
    <SafeControl Src=”~/UI/*”¬† IncludeSubFolders=”True” Safe=”True” AllowRemoteDesigner=”True” />
  9. Restart IIS, navigate to a page that uses the page layout and you should see your User Control

Because we created a IIS Application under our SharePoint web site and mapped our VS2008 projects .dll output path to our SharePoints web site, updates are extremely simple.

  1. .ascx changes:                modify, save in VS2008 and refresh sharepoint browser
  2. .ascx.cs changes:          modify, save, build  in VS2008 and refresh sharepoint browser

Posted in .NET 2.0, .Net 3.0, WSS 3.0 | 4 Comments »

SharePoint Authentication: FireFoxs works but IE doesn’t

Posted by Clayton James on May 20, 2009

I was having a great deal of pain on a new SharePoint development server recently. Environment = Windows 2008, IE7.


  1. Create a SharePoint web application with a host header on port 80. Create a site collection
  2. Update host file (or DNS) with new host header entry
  3. In IE make sure the web application is in the Intranet Zone
  4. Open up browser in IE navigate to site using host header and the authentication dialog login is displayed.
  5. Enter my credentials 3 times and receive a 401.1 and an entry in the Security Event log
  6. If I open FireFox and browse to the web site the authentication dialog is displayed
  7. I enter my credentials and I can log in fine
    Note: To get rid of the authentication prompt in FireFox
    1. Open FireFox and in the address type about:config
    2. Find the entry network.automatic-ntlm-auth.trusted-uris
    3. Set the Key’s value to a comma seperated list of trusted URIs i.e your host header
  8. So FireFox is fine but IE is having issues



I finally stumbled across a blog article from Brian Farnhill and Ishai Sagi that lead me to the solution.

You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or IIS 6

In my case I am using IE 7 and while the Solution/Workaround discusses two separate methods and states that method one is preferred, I could only fix my issue upon completing method 2

Posted in MOSS 2007, Office 12, WSS 3.0 | 3 Comments »

Sign in as a Different User

Posted by Clayton James on May 7, 2009

This little feature has caused myself so many problems for different clients. Some of the main issues I have come across include:

  • Still runs .Net code under the person who has logged into the computer
  • Creates authentication issues for end users when trying to open an Intranet bowser. Have to remove their user profiles to fix

I recommend to anyone now to¬†find the IExplore.exe (right click your shortcut and select Properties, then click the¬†¬†“Find Target” button), right click¬†and¬†select the¬†“run as”. Enter the credentials of the user you wish to log in as.

This still won’t run .Net code under the¬†new credentials you have entered but I have not come across any authentication issues using this approach so far.

Posted in WSS 3.0 | 1 Comment »

Non-Admins View Site Usage Reports

Posted by Clayton James on May 5, 2009

How to get non-admins to view your site collection and site usage reports

Site Collection Admins or user will Full Control can view Site Collection and Site Usage Reports.  So if you want other users to access these reports you can do the following:

  1. Create a custom site permission level and select the “View Usage Data” check box
    Note: this will also select the “View Pages” permission
  2. Create a new Group called something like “Usage Report Viewers” and assign the permission level you created above to the group
  3. Add the people you want to view the reports
  4. Provide the users with links to the report pages
    1/ http://sitecollection/_layouts/SpUsageSite.aspx Рview site collection reports
    2/ http://sitecollection/_layouts/SpUsageWeb.aspx Рview site reports

Use a web part to display the links and above and audience targeting so only the users in the SharePoint group “Usage Report Viewers” see the web part.

Posted in WSS 3.0 | 6 Comments »

Tech.Ed 2008…that’s a wrap

Posted by Clayton James on September 7, 2008

It has been a big week!

I taught a two day pre-conference course for Microsoft on building Internet sites using the SharePoint platform. We covered many areas including:

  • Architecture
  • Custom master pages, page layouts, css
  • Web parts
  • Optimisiation. IIS compression, caching, loading core.js
  • Content deployment
  • Extending publishing sites

It was a great couple of days that was also extremely busy with 34 students.

I went to a lot of SharePoint sessions this year and met some leaders in the industry. Todd Bleeker, Ishai Sagi, Ben Curry, Andrew Coates, Joel Olsen .

Todd pioneered SharePoint development by writing the first WSS 3.0 development book (it is my favourite SharePoint development book).

I also went to a Silverlight session. It seemed more a designers sessions than a coders session and I wasn’t really impressed. It demonstrated the expression suite. It is only beta 2 but stills seems lacking in VS integration (I don’t want another product to develop applications) and controls. Lots of hand coding in xaml.

And guess what happened this year…..we didn’t have to wait and get scanned in before sessions. That’s right…we had RFID chips which scanned us into rooms automatically. Great work was completed by the Breeze team in coordinating and brining this to reality.

Posted in .NET 2.0, MOSS 2007, WSS 3.0 | 1 Comment »

Error – Custom EditForm.aspx with EventHandler

Posted by Clayton James on August 27, 2008

I have been pulling my hair out for the last couple of hours trying everything possible. Thankfully came across this hotfix.


  • Creat a custom edit form in SharePoint designer
  • Create an event handler for ItemUpdating in Visual Studio and bind it to the list that has the custom edit form
  • Whenever you try to update a list item you receive the following error message
    “The data source control failed to execute the update command”

¬†“This hotfix fixes the following issue that was not previously documented in a Microsoft Knowledge Base article:

You design a project that contains a Windows SharePoint Service 3.0 list. The list uses a custom list form. Additionally, you design the project to display an error message when an ItemUpdating event is triggered. However, when you update an item in the list, the custom error message is not displayed. Instead, you receive the following error message from Windows SharePoint Service 3.0:

The data source control failed to execute the update command”

I haven’t applied it yet but it is exactly my problem.

UPDATE: 12/Sep/2008
This hotfix has fixed my problem. I am very happy ūüôā

Posted in WSS 3.0 | 9 Comments »

New U2U CAML builder

Posted by Clayton James on August 11, 2008

Kudos to Karine from U2U. She has come up with a new version for building CAML queries.

I have used the previous version of the U2U CAML Builder and have recommended it to others. This is the only way I chose to build CAML queries.

Download and let CAML become your friend ūüėČ

View the great new features and download here.

Posted in MOSS 2007, WSS 3.0 | Leave a Comment »

Site Columns Gallery Error

Posted by Clayton James on August 4, 2008

I was receiving this error the other day when trying to access the Site Column Gallery.

Object reference not set to an instance of an object.   at Microsoft.SharePoint.ApplicationPages.FieldListRenderer.Render(HtmlTextWriter output)
¬†¬† at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) ……..

It turns out that if you create a site column using the object model it capitalises SITES in the url.

The root problem was with the request Url we used to open a SPSite/SPWeb.  It turns out that the request Url you use to construct a SPSite is *case sensitive* to the URL the way it is specified in SharePoint when it comes to creating SPField objects programmatically.  I know that seems a little hard to believe but we ended up driving this bug through PSS and after getting our Content DB demonstrating the problem into MS hands they walked through their code and identified the problem in the code behind mngfield.aspx and a requirement that any fields created via WSS must have been done so through an SPSite/SPWeb with case that exactly matches the target site.

One additional thing we found through this two month adventure researching this bug, you can see the fields in a root site collection via mngfield.aspx *if* you view the Site Column gallery from a sub site of the site collection where mngfield.aspx is returning the Unknown Error/Null reference exception.

Here is how you can determine if the fields you created have the appropriate case-sensitive scope.

1. Create a sub-site under the site collection.

2. From that sub-site, select Site Actions -> Site Settings -> under Galleries -> Site columns

3. The mngfield.aspx page should display, and you will see all site columns from the parent site collection.

Note that the Source column on this page is a hyperlink to the site collection mngfied.aspx.¬† If you click this link you’ll be taken to the familiar Unknown Error.

4 Look for any site columns that your code added to the site collection.¬† Pay particular attention to the letter-case of the Source hyperlink Url.¬† If you’re hitting the same issue we found, you’ll note that the hyperlink Url case does not match the case of the actual site.

Basically there is a line of code in the code behind mngfield.aspx that does a check something along the lines of “field.Scope == web.ServerRelativeUrl”.¬† The ‘==’ op was a poor choice as it doesn’t handle mixed cases.

Once a Site Column has been created via WSS using a SPWeb instance that was constructed with mis-matched case that column is broken, it cannot be fixed.¬† You’ll have to delete it and recreate under a SPWeb that was constructed either a) with a request Url of appropriate case or b) the safer option is to construct SPWeb/SPSite instance using their GUID constructor since that forces a Url lookup which will always be accurate.

So to fix this you need to navigate to the fieldedit.aspx page in the layouts directory, pass in the field name and then can you can delete the problematic site column.
e.g.  http://moss/sites/companyxyz/_layouts/fldedit.aspx?field=tt

Posted in MOSS 2007, WSS 3.0 | 9 Comments »

CustomAction & UrlAction

Posted by Clayton James on July 30, 2008

Some more CustomAction elements I have come across include:
– Rights: You can set a Rights property so only people with these rights can view the Custom Action
      You can also remove existing CustomActions based on rights
– RegistrationType and RegistrationId: I have previously set these to lists, however you can even set them to file types. So only files with a .html extension will see this custom action in the ECB menu


Here is some great information from Jan Tielens Blog.

I am including the content as I always reference it.

MSDN documentation also.

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
        Title=”My Link”
        <UrlAction Url=”_layouts/mypage.aspx”/>

If you build some functionality in the mypage.aspx, in many scenarios this page will need to know from which list the link originated. This can be done by using URL tokens in the UrlAction element:

<UrlAction Url=”_layouts/mypage.aspx?listid={ListId}“/>

The {ListId} URL token will be automatically replaced with the ID of the list, in which the menu item is shown. In the mypage.aspx, you can retrieve the value of the listid parameter by making use of the QueryString. Once you’ve got the ID, the object model can be used to get a reference to the SPList instance of that list. According to the documentation on MSDN, the following URL tokens can be used:

  • ~site – Web site (SPWeb) relative link.
  • ~sitecollection – site collection (SPSite) relative link.
  • In addition, you can use the following tokens within a URL:
    • {ItemId} – Integer ID that represents the item within a list.
    • {ItemUrl} – URL of the item being acted upon. Only work for documents in libraries. [Not functional in Beta 2]
    • {ListId} – GUID that represents the list.
    • {SiteUrl} – URL of the Web site (SPWeb).
    • {RecurrenceId} – Recurrence index. This token is not supported for use in the context menus of list items.

    Unfortunately there is no token that will give you the URL of the page on which the feature’s link is being displayed. In many cases you want to have that URL to be able to redirect, after you’ve shown your custom functionality, to the originating page. SharePoint itself uses this technique a lot: in many URL’s you’ll find the Source parameter:


    The URL above points to the NewForm.aspx for the a Links list. Normally when the user fill’s out this form and clicks OK, this page redirects to the default view of the list. Because this link has the Source parameter, when the user clicks OK (or cancel), the page will redirect to the default.aspx instead. You can add the Source parameter to a lot of pages in SharePoint, giving you full control over the redirecting.

    So the issue is: we want to include the URL of the originating page in the UrlAction element of the feature’s CustomAction, but all we get are a bunch of ID’s and some URL’s that are not useful for this scenario. As usual peeking in the machine room of SharePoint itself can give you some good ideas to solve this issue. The SharePoint guys themselves sometimes use Javascript functions in the UrlAction, instead of ordinary hyperlinks. Thus with some clever use of Javascript, it’s quite easy to solve the problem:

    <UrlAction Url=”javascript:window.location= ‘{SiteUrl}/_layouts/mypage.aspx?List={ListId}&amp;Source=’ + window.location”/>

    The actual link is a Javascript function that will navigate to a specific URL. This URL is a concatenation of the URL of the page to display (including for example the ID of the list as a parameter in the QueryString), and the Source parameter which is dynamically set the current page’s URL. Et voila, the constructed link will point to your page, and the redirect will always point to the page you started from.

    Extra: this tric can also be used to overcome a bug in SharePoint that causes a URL token of a CustomAction to be replaced only once. So if you have used the ListID token two times in a UrlAction element, only one of the token’s will be replaced with the actual ID of the list. The user “FlatEric” (what’s in a name?) explains this in the Community Content of the How to: Add Actions to the User Interface article on MSDN.

    I found an ugly way to bypass this flaw:
    <UrlAction Url=”javascript:function process(){var site='{SiteUrl}’;var item={ItemId};window.location.href=site+’/Lists/MyList/NewForm.aspx?ID=’+item+’&amp;Source=’+site+’/Lists/myOtherList/DispForm.aspx?ID=’+item;};process();”/>

  • Posted in MOSS 2007, WSS 3.0 | 19 Comments »

    Master Detail View – Data View Web Part

    Posted by Clayton James on May 21, 2008

    I have some time to kill as I sit in a Melbourne apartment waiting on a phone call to hopefully receive Internet access. So I thought I would write a blog entry (you know‚Ķ.turn a negative into a positive :)). But I will have to wait for reconnection before I can post this entry ūüėČ

    I was asked a question recently about creating a master-detail form for employees and their work resume history. I immediately thought of InfoPath but a requirement was it needed to be in the browser. Unfortunately the infopath master detail control doesn’t render in the browser so after some thought…out came the lovely Data View Web Part (DVWP). So this is how the story goes…

    1. Create a Resume Details list. Each row in this list must contain a column that links it back to the parent list. In my case Full Name.

    2. Create a blank web part page

    3. Open the site in SharePoint designer and open the blank web part page you just created and click in the top Header web part zone


    4. Click the menu Insert –> SharePoint Controls –> Data View

    5. You will notice on the top right hand pane the Data Source Library is displayed. Select the Employees list and drag it into the Data View Web Part.


    6. Edit the columns of the web part to include what you want. I have a column called Full Name that I want displayed.

    7. Now click in the Footer web part zone and Insert another Data View Web Part.

    8. Drag the Resume Details list in the Data View Web Part and edit the columns as shown


    9. The next thing for us to do is create a connection between the two web parts so when I select an Employee their resume details are displayed. Right click the Employees DVWP and select Web Part Connections.

    10. You should see this dialog.

    11. Click Next until you come the following dialog. Select the column that you want to make the connection between the two web parts.

    12. Create a hyperlink on the connected field

    13. Then click next and Finish the web part connection

    14. Save the page in SPD and open the page in IE. You will now see the following screen. When you select an Employee the name is passed through to the Resume Details DVWP and filters the associated records


    15. Now…what if you wanted to edit the details right here in the page…simple when using the DVWP. Go back to SPD and select the change layout option.


    16. Select the following layout which is a Tabular Form Style. Don’t’ worry about the breaking of web part connections message. Everything should work fine.

    17. Then select the Data View Properties and select the Editing tab and select all the check boxes and click OK.


    18. Save the page and then view in the browser

    19. Ok…so all is good. Now your optional exercise. Put in place some conditional formatting and maybe a Form Web Part passing in text values.


    Posted in WSS 3.0 | 44 Comments »

    Developing ASP.Net 2.0 Code Behind pages for SharePoint: Using VSeWSS1.1

    Posted by Clayton James on April 13, 2008

    This is a guide that will take you through steps in creating a code behind file in Visual Studio for SharePoint development. Full credit to Andrew Connell on his blog entry which demonstrates this process by manually creating files for the deployment process.

    The difference with this article is that I wanted to complete the process using Microsoft’s Visual Studio Extensions WSS 1.1 (VSeWSS1.1) tool. Why, because I think this is the tool that should be used when doing any SharePoint development due to its integration with VS.Net, variety of templates, debugging integration, nice wsp viewer, auto generation of features and solutions, and it will continue to evolve over time.

    1/ First we need a Content page (.aspx) that will host our ASP.Net controls. Content pages need to conform to SharePoint master pages PlaceHolderContols. So a good place to create one is in SharePoint Designer.

    To create a Content page for SharePoint you can open SharePoint Designer and select File –> New –> Create from master page.This will create a blank content page as shown:

    This page has no asp Content controls so you can go and add one.
    <asp:Content ContentPlaceHolderId=”PlaceHolderMain” runat=”server”></asp:Content>

    Inside the content control you can add html markup as shown below


    3/ Copy the html (ctrl-A) from SharePoint Designer into notepad and save the physical file as CodeBehindDemo.aspx.

    4/ Open up Visual Studio and create a new Project and select the Empty SharePoint project and name it accordingly (Note: you need to install VSeWSS1.1 to get these templates).

    5/ Once the Project is created right click the project and select Add New Item and select the Module template.

    6/ Copy the CodeBehindDemo.aspx to the Module1 folder so it looks like the image below. Then create a new class file called CodeBehindDemo.cs. This will obviously be our code behind file.

    7/ Write the following code in the CodeBehindDemo.aspx page. We need to explicitly declare the asp.net controls in the class file as the .aspx and .cs files are not compiled into a single (partial) class.

    8/ Back in our .aspx page we need to reference our code behind class with the following page directive.
    <%@ Page Language=”C#” masterpagefile=”~masterurl/default.master” title=”|”

    inherits=”SharePointCodeBehindPages.CodeBehindDemo, SharePointCodeBehindPages, Version=, Culture=neutral, PublicKeyToken=9f4da00116c38ec5″ meta:webpartpageexpansion=”full” meta:progid=”SharePoint.WebPartPage.Document” %>

    Note: Check your public key token as yours will be different once you sign the assembly.

    9/ This is the code inside the Module.xml file.
    <?xml version=”1.0″ encoding=”utf-8″?>
    <Elements Id=”581c7ebb-03bd-4d7d-ad4a-4e7ff446d2ac” xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
    <Module Name=”Module1″>
         <File Path=”CodeBehindDemo.aspx” Url=”CodeBehindDemo.aspx” Type=”Ghostable” />

    <CustomAction Id=”A6DED79F-05A5-4b1a-BD27-10B1A4AAC737″
         Title=”Code Behind Demo”
         Description=”Code behind example”>
              <UrlAction Url=”~site/CodeBehindDemo.aspx” />

    10/ This is the code that is inside the Feature.xml file

    <?xml version=”1.0″ encoding=”utf-8″?>
    <Feature Id=”39fd665e-e168-42fe-ab11-ebea99e0a378″ Title=”Module1″ Scope=”Web” Version=”″ Hidden=”FALSE” DefaultResourceFile=”core” xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
         <ElementManifest Location=”Module1\Module.xml” />
         <ElementFile Location=”Module1\CodeBehindDemo.aspx” />

    11/This is the code inside the manifest file

    <?xml version=”1.0″ encoding=”utf-8″?>
    <Solution SolutionId=”e8fa762e-9f02-4646-9fde-cf17ed7288d6″ xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;
    <FeatureManifest Location=”Module1\feature.xml” />
    <Assembly DeploymentTarget=”WebApplication” Location=”SharePointCodeBehindPages.dll”>

    <SafeControl Namespace=”SharePointCodeBehindPages” Safe=”True” Assembly=”SharePointCodeBehindPages” TypeName=”*” />

    12/ Before we create and deploy the solution first build the project, make sure you don’t receive any errors and then check the new WSP View in Visual Studio to make everything is fine. You made need to click the Refresh button to display the wsp structure. One of the nice features about the extensions is that it is integrated with Visual Studio so if one of the .xml files has an error then it is displayed in the Error List pane and nothing is displayed in the WSP View, it is just blank. Remember to click the refresh button.

    13/ Now all that is needed is to deploy the Solution (.wsp) to the farm. Very simple, right click the project and select Deploy.

    14/ Make sure everything is successfully built and deployed

    15/ Once built successfully you can view the .wsp file which is located in the projects bin/debug folder
    16/ Ok, now lets go and test the page in SharePoint. We have a nice Custom Action we can click that will take us to the page.


    Enter you name and click the button.


    16/ So there you have it. A code behind page built in Visual Studio all wrapped up in a nice solution (.wsp) for deployment across the farm using the new Visual Studio Extensions for WSS 1.1 tool.

    Posted in WSS 3.0 | 57 Comments »

    Registering SharePoint Event Handlers

    Posted by Clayton James on April 2, 2008

    The first thing you want to do if you are writing event handlers for SharePoint is download the VSeWSS 1.1. This has a whole bag of goodies for us SharePoint developers  including a nice template for creating event handlers. Unfortunately it is only available in VS2005.

    There are basically two ways you can register an event handler to a SharePoint list or content type.

    1. Features – declarative approach
    2. Features and OM combined

    Ok, so when would you use one instead of the other.

    1. Features
      Basically you can use the Features declarative model when you want to register an event handler to all lists of the same type (ListTemplateId). If the ListTemplateId = 101 (Document Library) as shown below then when the Feature is installed and activated then the event handler will associated to all document libraries in the site.
      Everything is declared in the ElementsManifest.xml file.
      ¬† <Receivers ListTemplateId=”101″>
            <Assembly>SimpleEventHandler, Version=, Culture=neutral,
      ListTemplateId: This specifies which list to associate the event handler. 101 = document library. This is an all or nothing approach which means I can not associate the event handler to only one document library.
      ItemAdded: This is the event that will be raised when this action takes place.
      //Override the ItemAdded event and add your own code
           public override void ItemAdded(SPItemEventProperties properties)
               SetSecurityForNewItem(properties.ListItem.File, properties.ListItem.ParentList);
      Assembly, PublicKey Token, Class: Self explanatory. The event handler must be installed in the GAC before is can be associated to a list.
      SequenceNumber: This allows you to have multiple event handlers registered and specifiy their order of execution.
    2. Features and Object Model
      In this approach we have the ability to register our event handler to only one (or more) list/content type. Our solution (.wsp) would manage the process of installing our event handler assembly into the GAC and activate the Feature. When the Feature is activated we can run a Feature Receiver to attach our event handler to a specified list as shown below.

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        SPWeb web = properties.Feature.Parent as SPWeb;
    ¬†¬†¬† web.Lists[“Appointments”].EventReceivers.Add(
    ¬†¬†¬†¬†¬† “CJ.SharePoint.Eventhandlers, Version=, Culture=neutral, PublicKeyToken=3a29000ff02kt1bn”,
    ¬†¬†¬†¬†¬† “CJ.SharePoint.Eventhandlers.ItemPermissionsEventHandler”);

    Side note on Event Handlers
    If the event handler modifies the current list or current list item then you must call the this.DisableEventFiring() method before committing the change, and then before you leave your event handler code call this.EnableEventFiring() method to turn events back on. This stops recursive event firing from occurring where the list item is being modifed by the event handler which in turn raises the event handler again, thus causing an infinite loop.

    Posted in WSS 3.0 | 8 Comments »

    Custom web.config settings in SharePoint

    Posted by Clayton James on March 19, 2008

    I have come across two ways to modify the web.config with custom nodes when using SharePoint. Yes, I know SharePoint solutions (.wsp) allow you to update web.config for safe control entries and other areas but this model doesn’t allow for any modification you want…lets say a WCF service <system.serviceModel>.

    Option 1
    You can use the SPWebConfigModification class that is inside the Microsoft.SharePoint.Administration.dll. Its purpose is to write nodes and attributes into the web.config file. This is a great approach when you want to deploy your custom settings via a features/solutions deployment.

    SPWebService service = SPWebService.ContentService; SPWebConfigModification myModification = new SPWebConfigModification(); myModification.Path = “configuration/SharePoint/SafeControls”; myModification.Name = “SafeControl[@Assembly=’MyCustomAssembly’][@Namespace=’MyCustomNamespace’][@TypeName=’*’][@Safe=’True’]”; myModification.Sequence = 0; myModification.Owner = “User Name“; myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; myModification.Value = “<SafeControl Assembly=’MyCustomAssembly’ Namespace=’MyCustomNamespace’ TypeName=’*’ Safe=’True’ />”; service.WebConfigModifications.Add(myModification); /*Call Update and ApplyWebConfigModifications to save changes*/ service.Update(); service.ApplyWebConfigModifications();


    So the above code would go in a FeatureReceiver event when activated and removed when deactivated.

    Option 2
    If you want to write custom nodes into a web.config when the web application is first created you could also do the following.

    When a Web Application is first created WSS copies the web.config file from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG to the root folder of the Web Application. But before this file is copied it checks the CONFIG directory for any xml file that has a name in the format webconfig.*.xml and merges the contents with the web.config.

    So you would create a file called webconfig.myname.xml and save it to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG

    However, this approach will not modify existing web applications.

    webconfig.myname.xml contents:
    <?xml version=”1.0″ encoding=”utf-8″ ?>
    <add path=”configuration/appSettings”>
    <add key=”MyFilePath” value=”C:\temp\path\” />
    <add path=”configuration”>
    <connectionStrings />
    <add path=”configuration/connectionStrings”>
    <remove name=”MySqlServerConnection” />
    <add name=”MySqlServerConnection” connectionString=”server=[server];database=
    db];Integrated Security=SSIP;” providerName=”System.Data.SqlClient” />

    So this needs to be completed on each web front end server. So to eliminate the manual approach again you can and package this up into a solution so WSS manages the deployment across the farm.
    Add the file to a solution. A file to be deployed to the CONFIG folder can be inserted by using the <RootFile> element:

    manifest.xml example:
    <Solution xmlns=”http://schemas.microsoft.com/sharepoint/&#8221; SolutionId=”GUIDHERE”>
    ¬†¬† <RootFile Location=”CONFIG\webconfig.myname.xml”/>
    <!– rest of solution manifest here
    <FeatureManifests>… and other elements


    Posted in WSS 3.0 | 21 Comments »

    WSS Web Part Resources

    Posted by Clayton James on January 4, 2008

    WebPart.PartCacheWrite Method

    Book Excerpt
    Microsoft SharePoint Products and Technologies Resource Kit
    Web Part Architecture
    Strong-Naming Assemblies
    Code Access Security
    Creating a Web Part
    Debugging Web Parts
    Creating Child Controls on a Web Part
    Web Part Tools

    Web Parts and Session State (when not to use session state)

    Posted in WSS 3.0 | Leave a Comment »

    WSS Resource Center

    Posted by Clayton James on December 1, 2007

    I came across this gold nugget today.

    SharePoint Server 2007 Developer Portal

    With the ever increasing resources related to the SharePoint 2007 platform it can be full time job just maintaining an up-to-date list. Thankfully it seems MSFT are now doing this for me J

    Check out Sezai’s blog also for a list of great SharePoint resources.

    Posted in WSS 3.0 | Leave a Comment »

    WSS Security

    Posted by Clayton James on October 7, 2007

    SharePoint Groups
    SharePoint groups are created at the site collection level and are available to be used in any site in the site collection. You cannot have SharePoint groups inside a SharePoint group, but you can have an active directory group in a SharePoint group.

    Permission Inheritance
    Each object inherit permissions from parent by default.

    • Site collection √† Site √† Doc Library √† Folder/Document

    Permission inheritance is an all or nothing approach. If you want to add custom permissions to child objects then it becomes detached from the parent object. If you decide to switch back to inheritance permission all of your unique permission will be discarded.

    Create Custom Permission Level

    1. Site Actions à Site Settings
    2. Users and permissions à Advanced permissions
    3. Select Manage Permissions of Parent from the Actions menu
    4. Select Permissions Levels from the Settings menu
    5. Click Edit Permissions Levels à Add a Permission Level
    6. Type a name and description for new permission level and select the permissions to assign.

    Managing Authorisation
    Create and use SharePoint groups as often as possible. Adding individual user accounts increases work to maintain security.

    User Rights for Web Applications
    Server admins can control which permissions can be set at site permission levels that exist in a web application.
    CA à Application Management à User Rights for Web Applications

    Policies for Web Applications
    Allows server admins to control permissions to all objects in all site collections in a web application for users or domain groups. SharePoint groups are defined for each site collection sot that are not available here . This provides a good place to globally (web application) implement security constraints for users or domain groups.

    Object Model

    Posted in WSS 3.0 | 2 Comments »

    Formuals for calculated columns in WSS

    Posted by Clayton James on September 28, 2007

    I get asked and google/live regulary on using formulas in calcualted columns. I have just come across this great article on using formulas in calcualated columns.

    This is so helpful!

    Posted in Office 12, WSS 3.0 | 1 Comment »

    Custom WorkFlow Activities in SharePoint Designer

    Posted by Clayton James on September 10, 2007

    I have been doing some research in creating custom workflow activities and then using them from SharePoint Designer. If you are looking to do the same then these are the places you will need to look at first.

    Great post from the SPD team explaining all concepts and what is required.

    Great example in the SDK


    Open and build the ECMActivites Visual Studio solution and then follow the steps in the above URL.
    Note: These files/solutions are installed with the WSS/MOSS SDK so if you don’t have this directory structure then you need to download and install the SDKs.

    The ability to write custom WF solutions and expose them inside SPD is very powerful and another great extensible feature.

    Posted in WSS 3.0 | 2 Comments »

    Dependent Dropdown control

    Posted by Clayton James on September 6, 2007

    This has been a question I have received many times. Why didn’t the wss team release a Dependent Dropdown control that has a Parent/Child relationship?

    Yah…, good question.

    Thanks to one of my Data Cogs colleagues Mark Daunt I can offer a solution….a .wsp solution that is.

    You can check it all out here.

    Posted in WSS 3.0 | 1 Comment »