Tuesday, December 04, 2007

Infopath cannot add the event handler

While working in Infopath 2007 managed code when i tried to attach managed code to existing
form i got the following error:

Error :

Infopath cannot add the event handler

Infopath cannot create the visual basic or C# project

The location for the visual basic or C# project cannot be found or cannot be accessed


So next steps is to search internet , well no luck in that too . Then i decided to try different things with my form settings and shazam!!! got the form working .

Solution in my case :
  • Go to Tools -> Options ->Design Tab
  • Check the language for programming /select the desired language
  • Go to Tools -> Form Options -> Programming Section
  • Select the programming language which you selected in previous settings

That should be good enough to make you go forward.

In my case there was difference in language settings which caused all these errors, which might be in your case too.

Happy Infopath Programming!!!!

Friday, November 30, 2007

Writing Managed Code for Browser based Infopath 2007 Form

Ever wondered how to write managed code for Browser based infopath form , check this out :

http://www.microsoft.com/downloads/details.aspx?familyid=db1d99d9-0a31-45de-8efb-16c75e194dc3&displaylang=en

Steps in Nutshell :

  • Change the form security to full trust

Tools -> Form Options -> Security and Trust -> Full Trust

  • Publish Infopath Form to Network Share

  • Upload form to the server

Central Administration > Application Management > Manage Form Templates

  • Active form for desired site collection

  • Access the form using url of following format :

http://"server name"/_layouts/formserver.aspx?xsnlocation="site collection address "/formservertemplates/"form name".xsn&openin=browser&QueryParametername="value"

Tuesday, November 27, 2007

Content Deployment MOSS Hurdles

Collection of hurdles which you might encounter while setting up content deployment in SharePoint 2007

http://soerennielsen.wordpress.com/2007/06/19/the-long-path-to-content-deployment/

Content Deployment in Three Steps ........

Step 1:
Allow Incoming Content Deployment Jobs on the Production Site

Step 2 :
Create Content Deployment Path and Job from Staging to Production

Step 3 :
Run Content Deployment Job


For step by step instruction check out the following article :
http://blogs.msdn.com/jackiebo/archive/2007/02/26/content-deployment-step-by-step-tutorial.aspx

Content Deployment Failed Error

You started with content deployment , defined the content path and job . Everything looks good till you actually run the job and bang the mighty long error

"Failed to compare two elements in the array. at System.Collections.Generic.ArraySortHelper`1.QuickSort[TValue](T[] keys, TValue[] values, Int32 left, Int32 right, IComparer`1 comparer) at System.Collections.Generic.ArraySortHelper`1.QuickSort[TValue](T[] keys, TValue[] values, Int32 left, Int32 right, IComparer`1 comparer) at System.Collections.Generic.ArraySortHelper`1.Sort[TValue](T[] keys, TValue[] values, Int32 index, Int32 length, IComparer`1 comparer) at System.Collections.Generic.ArraySortHelper`1.Sort(T[] items, Int32 index, Int32 length, IComparer`1 comparer) at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer`1 comparer) at System.Collections.Generic.List`1.Sort(Int32 index, Int32 count, IComparer`1 comparer) at System.Collections.Generic.List`1.Sort(IComparer`1 comparer) at Microsoft.SharePoint.Deployment.WebSerializer.GetDataFromObjectModel(Object obj, SerializationInfo info, StreamingContext context) at Microsoft.SharePoint.Deployment.DeploymentSerializationSurrogate.GetObjectData(Object obj, SerializationInfo info, StreamingContext context) at Microsoft.SharePoint.Deployment.XmlFormatter.SerializeObject(Object obj, ISerializationSurrogate surrogate, String elementName, Boolean bNeedEnvelope) at Microsoft.SharePoint.Deployment.XmlFormatter.Serialize(Stream serializationStream, Object topLevelObject) at Microsoft.SharePoint.Deployment.ObjectSerializer.Serialize(DeploymentObject deployObject, Stream serializationStream) at Microsoft.SharePoint.Deployment.SPExport.SerializeObjects() at Microsoft.SharePoint.Deployment.SPExport.Run() *** Inner exception: Object reference not set to an instance of an object. at Microsoft.SharePoint.SPFeature.EnsureProperties() at Microsoft.SharePoint.SPFeature.get_TimeActivated() at Microsoft.SharePoint.Deployment.WebSerializer.ExportFeatureComparer.System.Collections.Generic.IComparer.Compare(ExportObject exportObject1, ExportObject exportObject2) at System.Collections.Generic.ArraySortHelper`1.QuickSort[TValue](T[] keys, TValue[] values, Int32 left, Int32 right, IComparer`1 comparer)"

OR

" Content deployment failed.The exception thrown was 'System.InvalidOperationException' : 'Failed to compare two elements in the array.'

Solution :
The exception basically means that some of the features activated at the site collection level no longer exist on disk. Their feature definition files have probably been deleted. This can easily occur if you delete some features from your solution packs without deactivating/reactivating all features on deployment .

So pin point the features causing trouble and remove it and you will be good to go .

Tuesday, October 30, 2007

Cross Browser Support for MOSS

The newer version of sharepoint , MOSS 2007 has better cross browser compatibility than the older version . It supports the following browswer :


Windows
Firefox 1.5+
Netscape 8.1+
Mozilla 1.7+
Macintosh
Safari 2.0+
Firefox 1.5+
Unix/Linux
Firefox 1.5+
Netscape 7.2+

Check out the following article to completely understand the browser compatibility and feature support by Level 2 browser :

http://technet2.microsoft.com/Office/en-us/library/ff6c5b8c-59bd-4079-8f0b-de4f8b4e0a861033.mspx?mfr=true

Wednesday, October 17, 2007

Timer Job Failed

ERRORS :
  • The job to enable features on existing sites failed
  • Application Server Administration Service Timer Job Failed

In such cases check the Windows Timer Service running in server , also check the credentials the timer is running which might be a reason of the Jobs failing in server.

Wednesday, October 10, 2007

The file web.sitemap required by XmlSiteMapProvider does not exist

I am using a custom XMLSiteMapProvider where in i have defined a web.sitemap file with urls.
The application worked fine for administrators but i got this error when i tried other users. I am using this control in a SharePoint 2007 Page . After lots of trial it came to my notice that actual error was not identification of the file .The problem was that the normal sharepoint user didn't had enough permission to access the web.sitemap file in web server .

This worked once i gave autheticated user access to the file,kind of fishy though , as i am not expecting this behaviour.

Friday, October 05, 2007

CSS not working on LinkButton

This was my issue , i had defined link button in asp.net like this :


_linkNewIncident = new System.Web.UI.WebControls.LinkButton();
_linkNewIncident.Text = "Creat New Incident";
_linkNewIncident.Click += new EventHandler(linkNewIncident_Click);
_linkNewIncident.CssClass = "HelpDeskLink";

and corresponding CSS as :
.HelpDeskLink { color:white ; font-weight :bolder ; font-size :x-small ; }

.HelpDeskLink a { color:white ; font-weight :bolder ; font-size :x-small ; }


when i ran the application , my links were still blue and was not reflecting any CSS behaviour which is supposed to be white as per my CSS :-(


After some search i got the solution .

Solution : Define "CSS Pseudo-classes"

I modified my CSS style class to the following and it worked ..


a.HelpDeskLink:link
{
color:white ;
font-weight :bolder ;
font-size :x-small ;
}

Monday, October 01, 2007

Server error: This item cannot be deleted because it is still referenced by other pages

You might get this error when you try to delete from the _catalogsmasterpage directory ,. Microsoft has provided a solution which doesn't look convincing at all :

check : http://support.microsoft.com/kb/926812

I used a different method:
  • Open the Master gallery in Explorer view
  • Create a Directory named "Delete"
  • Cut all the un-wanted Master Pages and paste it inside the "Delete" directoty
  • Delete the "Delete" Directory

And you got rid of all the unwanted pages .

Friday, September 28, 2007

Access Denied While Create Page Action

My user came back to me in morning and said that he is not able to create a page and was facing "Access Denied" error, i was amazed as the user had full control to the site. So i tried it with my ID and BANG same error. I was not able to make page too havig the same "Full Control" access.

After a complete half day of search and trying different things gladly it worked ,saved my weekend fun.

Solution which i used to get over the error is to add my ID to the "Administrators" group of site and it's all fixed.

Am not sure weather it is something by architecture of other issue but it saved my day.

I got one solution which still needs to be tested :
Check out :
http://wss.asaris.de/sites/walsh/Lists/WSSv3%20FAQ/DispForm.aspx?ID=1148

Thursday, September 20, 2007

Unable to open Page due to Web Part Error . "Saviour" Web Part Maintenance Page

At some day you decide to test your new webpart and unfortunately web part bombs badly and you end up with page which looks something like this :




Now second thought is to open the page using Sharepoint designer and removing web part , but to the height of disappointment even Designer throws all kind of error.You are all stuck thinking "How can i remove web part ? "

Well trick is to append your page url with querystring " ?contents=1 ".

So if your stuck url is http://localhost then append the query string
http://localhost?contents=1

This will take you to the saviour page "Web Part Maintenance Page" ,remove the webpart and have a happy day forward :)

Wednesday, September 12, 2007

Workflow Failed in SharePoint with Error: Failed on Start (retrying)

In case you are the unlucky one to get this error then i have couple of suggestions .One of them worked for me :)

Check out the 2 ways which might help you to overcome this error:

  • The workflow definition is invalid. :This can be figured out as SPD pops error message in such case

  • Changing the identity of the application pool to a user with administrative rights can cause the workflow to “fail to start“. If this sounds like something you've done, try changing it back to network service and try running the workflow again. (worked for me)

Check out the article by Jason Nadrowski

Tuesday, July 10, 2007

"An unexpected error has occurred" in MOSS 2007


Ever wondered what the heck is going on when you are popped with error "Unexpected Error" when developing on SharePoint, well this approach might make life simpler ,it made mine.

Make the following changes :

  • Open web.config of the site you are working on
  • search for "CallStack" attribute in safe mode section and change the value to "true"
  • Search for "CustomErrors" in System.web section and change the value to "false"


and take a sigh of relief atleast now you will have something on screen in developers language.

Tuesday, June 26, 2007

People Picker in MOSS 2007 unable to find user from Multiple Domain

When the sharepoint is installed in environment with multiple domains , the user profile import mechanism only imports the user from the domain in which the sharepoint server is installed.


For eg , if there are multiple domains Domain1.abc.com and Domain2.abc.com and sharepoint 2007 server is installed at Domain2.abc.com , in such case when user profile import is run in SSP , all the users from Domain2.abc.com are imported to user profile database.


when we try to use the people picker control to search for user present in Domain1.abc.com we don't get any results as shown below :



In order to import users from Domain1.abc.com , we need to define new import connection for the Domain1.abc.com and start user profile import once more .

Follow these steps :

  • Open SSP(Shared Service provider)
  • Go to User Profiles and Properties
  • Click on View Import Connections
  • Create New Connection
  • Add the following entries , also shown in figure below

Domain Name :Domain1


Auto discover domain controller(Selected)


Search Base :DC=Domain1,DC=abc,DC=com


Other as default*



  • Start full import and now you should get all users

Wednesday, June 13, 2007

Unable to add domain user to SharePoint 2007 Site

This behavior may occur if the user who you want to add is a member of a Microsoft Windows NT4.0 domain that is joined to your Active Directory forest. The Select users and groups -- Web Page Dialog dialog box does not support Windows NT 4.0 domains. You can use the dialog box to search for and add users who are members of a Microsoft Windows Server 2003 or Microsoft Windows 2000 domain. However, you cannot use the dialog box to retrieve user information from a Windows NT 4.0 domain.


Resolution :
Directly add the user ID to the "add user box" and assign permissions and press OK, this will add the user to the site.

Thursday, May 31, 2007

"MySite" not working SharePoint 2007

I was working on MySite today and while playing around i had no clue what i did but i was sure of one thing that i totally messed it up .

MySite stopped responding and after that only thing which came to mind is "SOS"

Anyways in case you end up in same situation which is very possible in the life of a computer geek , then simply follow the steps .


1)Open Central Administration ->Operations and create a new web application with "My Site Host" as template.
2)Well once you are done with creation of site the only thing remaining is to point the MySite to the new application URL as , so change the URL.

- Go to SSP

- click on "My Site Settings"

- Specify the new Url at "Personal Site Service"

That's It .Try accessing the MySite now.It's up and running.

Wednesday, May 30, 2007

Custom Activity for SharePoint Designer 2007

Every time you start workflow development there is big question in mind, Should i use Visual Studio or SharePoint Designer 2007 and you might end up visual studio if the workflow requirement is bit more than the "out of box" functionality of SPD.

Would'nt it be nice if i can plug in more functionality to Sharepoint Designer.

When MOSS 2007 came into market the impression was that SPD is not much extensible and is to be used for very simple workflow , but i am glad Microsoft didn't made it that stringent and have provided a way to attach custom activities to the SPD.

I have created custom activities in number of work flow scenario and belive me its great .I won't put my procedures in this blog as there are blogs where you can get the complete process. They helped me a lot of understand the "Custom Activities" development.

Here they are :

By Carlos Segura Sanz
http://www.ideseg.com/AddCustomWorkflowActivitiesToSharePointDesignerPart1.aspx
http://www.ideseg.com/AddCustomWorkflowActivitiesToSharePointDesignerPart2.aspx

John Holliday
http://johnholliday.net/archive/2007/03/27/Add-Your-Own-Custom-Workflow-Activities-to-SharePoint-Designer-2007.aspx

SharePoint Designer Team Blog http://blogs.msdn.com/sharepointdesigner/archive/2007/03/15/adding-activities-to-spd.aspx

Well majority of them speak about same stuff , but cross reference helps to make understanding much clear .

HAPPY WORK~FLOWING!!!!

Wednesday, May 23, 2007

People Picker Control for Infopath 2007

Ever wanted to have a people picker kind of control in Infopath form and that too in browser mode. Did i heard yes :) , well there is a Active-X control which takes care of this part named "Contact Selector Control".

Just follow the steps to get it working :

Add Contact Selector to Controls Pane

  • Click the "Add or Remove Controls " from the Control Task pane as shown in figure





  • Click ADD
  • Select Active-X
  • This will display a list of controls , select "Contact Selector" ,click Next
  • Select "Don't include a .cab file"
  • From drop down select "Field or Group(any data type) and click finish

DataSource for the Contact Selector control

  • Add non Repeating group named "group1"
  • Add a repeating Group names "Person"
  • Add following test field to the "Perosn " group (DisplayName,AccountId,AccountType)


Add Secondary datasource XMl file with details about the SharePoint Server , this is required by the form in order to validate the user against a particular sharepoint server .

  • Open Notepad and add the following Tag <Context siteUrl="http://<servername>"/>
  • Save the file as Context.xml
  • Add new connection as "Receive Type" and source of data as "XML"
  • Option “Include the data as a resource file” shoule be enabled


Drag control to the form and you are all set .


Best of Luck !!!!

Monday, May 21, 2007

MOSS 2007 Webcasts and Videos

I was planning to make a list of good webcast and video on SharePoint , Thanks to Steve Sofian for taking this initiative :-)

These are some good collection of sharepoint concepts :

http://www.sharepointblogs.com/ssofian/archive/2006/07/28/9532.aspx


Enjoy!!!!

Tuesday, May 15, 2007

People Picker not able to identify users in forest with multiple domain - SharePoint 2007

I am working on this issue from past 2 days and belive me it's very time consuming in case you dont get the solution ASAP . Thanks to Joel Oleson's Life blog which talks about the same.

To keep it short i would just give the problem statement and solution to get it working .


Problem Statement :
When Sharepoint server 2007 is installed in environment with more than one domain , there is a tendency of people picker control to search only in domain where the portal is installed .
E.G Consider following environment as example

Forest Name :test.com
First Domain :First.test.com
Second Domain :Second.test.com


In such case if you install sharepoint server in domain First.test.com , the people picker might not recognize users from Second.test.com.
So what could be done to make it work .

Solution Description :
Note : First make sure that there exist atleast a one way trust between the 2 domains(First.test.com /Second.test.com) and follow the steps.

First Step :
Run stsadm.exe to set the password used for encrytion/de-cryption

stsadm.exe -o setapppassword -password
eg stsadm.exe -o setapppassword -password testpassword


Second Step :

Format of command :
stsadm.exe –o setproperty -url {} –pn "peoplepicker-searchadforests" –pv {list of forests or domains}

The format of {list of forests or domains} is a list of

forest:DnsName,LoginName,Password
or
domain:DnsName,LoginName,Password

separated by semicolon.

As per our example the command is like

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsa
dm.exe -o setproperty -url "http://localhost" -pn "people
picker-searchadforests" -pv "forest:test.com;domain:First.test.com;domain:Second.test.com" ,{domainusername},{domainuserpassword}


Last step IISRESET might not be needed (i did that :) ).

And you are all set , try the People picker search and you get all the users.

Friday, May 04, 2007

Customizing MySite in SharePoint 2007

Well i was searching for a methodology to customize MySite in SharePoint 2007 and Volla!!! i got this excellent article:

Customizing MOSS 2007 My Sites within the enterprise

Thursday, April 19, 2007

Sunday, January 28, 2007

Customizing Asp.Net 2.0 application to look like a SharePoint 2007 Portal : Approach 2

As we saw in my previous blog , one of the simpler approach to achieve the “Consistent UI” in Asp.Net application when they are run together with SharePoint portal .


Now we will check out the second approach where we have the same “Financial Application” and we have following requirements:



  • The UI of the existing application must be similar to existing portal

  • The Application must be executed under the same context of SharePoint portal

In order to achieve these we need to perform following:


Consistent UI :
In order to achieve the same UI as of portal, we have to use the “Master Page “of the portal. Inherit all the .aspx page of your existing application from Master page of portal.

SharePoint portal Context:
In order to run the portal under SharePoint context, copy the complete application folder to “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS”

Let’s convert our existing “Financial Application “in order to adhere to the above mentioned requirement.


Step 1: Getting application to SharePoint Context


Copy the complete application folder of the “Financial Application” to


“C:\Program Files\Common Files\Microsoft Shared\web server

extensions\12\TEMPLATE\LAYOUTS”









Now we can access the same application under context of SharePoint portal, use the following URL

http://localhost/_layouts/financialapplication/default.aspx and we get the following page:




As we achieved one step of getting our application to the SharePoint context, our next step is to achieve SharePoint UI:




Step 2: Setting application UI to that of SharePoint


As mentioned above we can achieve the SharePoint UI by simply inheriting the master page of our portal. In order to achieve this lets open your “default.aspx” of “Financial Application “in Visual Studio 2005/Notepad.


In the page directive of “default.aspx “page add attribute:

MasterPageFile="~/_layouts/application.master" and add following directives:

  • <@ Assembly Name="Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>;

  • <@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" >;

  • <@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" >;

The page would be like this:




Once we are done with the master page reference we need to define the content of the page. As Master pages contains content placeholders we need to place complete “Form” section of our application to the appropriate content placeholder of the default.aspx. Lets define a content placeholder element in “default.aspx” page:


<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">asp:Content>

Lets copy the complete form elements from our default.aspx and add it to the ContentPlaceholder named “PlaceHolderMain”. Copy all elements of <form> tag as shown below:




And paste it inside the content placeholder.”Default.aspx” now looks like:




Let’s define the Title too using the ContentPlaceHolder “PlaceHolderPageTitleInTitleArea”


Add the following in “default.aspx” for defining title:

<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">Financial Application<asp:Content>

It seems we are done. Now when we try the same url http://localhost/_layouts/financialapplication/default.aspx

We get the page with SharePoint UI as shown below:


That’s it, 30 min of effort and your application seems to be a SharePoint application and now you can go forward and use the SharePoint context to achieve any tweaking with the SharePoint portal . You can get the code for Changed "Financial Application" from

http://www.box.net/index.php?rm=box_v2_download_shared_file&file_id=f_40004506

Saturday, January 27, 2007

Customizing Asp.Net 2.0 application to look like a SharePoint 2007 Portal: Approach 1

In any organization you can find plethora of application implemented, which are dependent /independent of each other. When such organization decided to move the portal way then the “AIM “ is to provide one “Window” for information for complete organization .This can be achieved by integrating the existing application with the portal application .In such case one important rule while implementing portal is to maintain “Consistent UI” across organization portal . The “consistent UI “site receives better acceptability by the end user. I got this requirement and wanted to share the simplicity of achieving this in SharePoint 2007 portal.

For showcasing this I have taken a web application which is a virtual “Financial application” for an organization .We will go forward and give this application “MASK OF SHAREPOINT”, doing that we achieve the important principal of portal acceptability “CONSISTENT UI”. There are number of approach which can be implemented to achieve. We will see both the case.

Let’s see how our application looks before we start our makeover:




As we see our application is a plain app which does basic computation.


First Approach:


In case we have independent application and just need a share point MASK in such case we can use “Page Viewer web part” .In Order to implement this , create a new SharePoint page in your SharePoint site .Site Actions->Create Page.


Name : Finance Application


URL : financeapplication
Page Layout: Blank Web Part Page



Press “Create”, you will get the page as shown below:




Click on “Add New Web Part” and select “Page Viewer Web Part” from the list.




Click “open the tool pane” in the web part to specify the finance application URL, and click apply.




You will get the “Finance Application“ page inside the “Page Viewer web part”, you might get the frame as the “Page Viewer Web part “ width and height is by default set to fit the web part zone .Feel free to modify the dimension of page viewer web part . Result page looks like:



This approach can be used in following situations:




  • When the application is completely independent and don’t need any information from the portal site i.e. it’s not required to run the Asp.Net application in context of the portal application

Second Approach:



This approach is advantageous when the application needs to “Run in the same context of SharePoint portal “


e.g.

  • Developing SharePoint administration custom page


We will see this approach in the next blog ;-). BREAK

Saturday, January 20, 2007

Hiding SharePoint 2007 List Context Menu Items


Am sure lot's of people would be wondering how to hide menu items of a list eg document libraries "Send to " menu item .



In olden days of SharePoint 2003 this used to be achieved using playing around with the OWS.jss file ,though the customization is same in SharePoint 2007 too but the file has been changed . Now the modifications needs to be done in CORE.JS file located at "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\CORE.JS"


Let's change the file and see the difference , In order to hide menu item e.g "Send to " search for function named "AddSendSubMenu()" in CORE.JS and comment the function call . as shown in figure below:




That's it check the menu in doc lib now , does it looks like mine:-)




NOTE: Make sure you take back up of Core.js file before making any change in order to prevent any server functionality malfunction.

Thursday, January 18, 2007

Error Loading workflow Visual Studio 2005



Have you ever faced this issue and wondering what's wrong with the editor.Well in my case the sharepoint references were missing .

Monday, January 15, 2007

Automate back Up Process MOSS 2007

I hope it's a pain for all the SharePoint geeks to get the back up of there site manually either using Sharepoint administration/Sharepoint designer/stsadm.exe tool .

I was thiking about it and wanted to make my life simpler so thought of writing a tool to automate the process and here it is .

This tool is very basic and only limited to complete backup . Granular level backup is not supported .I haven't taken care of all the cases so tool might fail in certain condition.So there is possibility that the back up might fail and you might get "Success" message . well sounds scary :) .Just make sure you check the back up atleast first time .

I have included a word file with configuration info .Also included the complete 15 liner class file in case you want to make it more stable.

This is a normal command tool and needs to be run with windows scheduler.

Tool is available at :
Download

Saturday, January 06, 2007

Registering Event Handler for list events

To register event handler for list events , create folder in the \template\features folder named "EventFeature" which contain a feature.xml file that specifies the scope and ID of the "feature" and element .xml file that the former file references.The feature file might look like the following :



< Feature>
< Scope="Web"
Title="Event handler"
Id="Create a GUID"
xmlns="http://schemas.microsoft.com/sharepoint/" >
< ElementManifests >
< ElementManifest location="element.xml" >
< /ElementManifests>
< /Feature>

The element.xml file registers the event handler assembly and associates it with a list type, for announcement list type is 104 as shown below:


< Elements >
< Receivers
< ListTemplateOwners="name of site definition using which this site is created and this list belongs to "
ListTemplateId="104" >
< Receiver >
< Name >EventHandler< /Name >
< Type >2< /Type >
< SequenceNumber >10000< /SequenceNumber >
< Assembly > "NameSpace name of assembly"
,version=1.0.0.0,Culture=neutral,PublicKeyToken="public key token of assembly"
< /Assembly >
< /Class >"ClassNameOfAssembly"< /Class >
< Data >< /Data >
< Filter >< /Filter >
< /Receiver >
< /Receivers >
< /Elements >

Once we are done with feature creation ,register feature using stsadm.exe tool present in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"

Run the following command to install feature :
stsadm -o installfeature -filename EventFeature\feature.xml

Run the follwing command to activate the feature:
stsadm -o activatefeature -filename EventFeature\feature.xml -url "url of the site"

That's it you are done with features ...just go forward and try adding ,deleting,editing in list and check weather it performs as per your expectations .

ENJOY!!! LIFE IS MUCH SIMPLER NOW :-)

Thursday, January 04, 2007

List Events in Windows SharePoint Services 3.0

Ever had these questions while working with lists/document library:
  • Is it possible to restrict users from entering invalid data?
  • Is it possible to have counters for files created ,deleted?
  • Is it possible to display users with "Custom Error" in case they try entering invalid data?
All these questions were kind of un-answered during days of SharePoint 2003 ,fortunately days have changed and Microsoft has solutions for it .Its the MOSS 2007/WSS 3.0 Events.

In WSS 3.0 events that are triggered by list allow you to hook up with code when the list itsms are added,changed or removed.
Events are divided in 2 category :
  • Events that fire before an action occurs :This allow you to perform custom validation or processing of data that is about to be added to the list,modified or deleted.
  • Events that fire after a certain action occurs
In WSS 3.0 it is possible to communicate responses back to the user interface.

You can create an event handler assembly using Visual Studio .NET by creating a class inhering from SPItemEventReceiver base class present in Microsoft.SharePoint.dll assembly.

using System;
using Microsoft.SharePoint;

namespace WSS.FirstTest
{
public class MyFirstEventhandler:SPItemEventHandler
{
}
}


This class will be instantiated by the WSS 3.0 when action occurs within the list. In order to define custom behaviour of these events we need to override the methods in SPItemEventReceiver class. Following method can be overriden:
  • ItemAdding
  • ItemAdded
  • ItemUpdating
  • ItemUpdated
  • ItemDeleting
  • ItemDeleted
  • ItemCheckingIn
  • ItemCheckedIn
  • ItemCheckingOut
  • ItemCheckedOut
  • ItemUncheckingOut
  • ItemUncheckedOut
  • ItemFileRenaming
  • ItemFileRenamed
  • ItemAttachmentAdding
  • ItemAttachmentAdded
  • ItemAttachmentDeleting
  • ItemAttachmentDeleted
We will override method ItemDeleting as sample.

public override void ItemDeleting(SPItemEventProperties property)
{
if(property.BeforeProperties["Amount"].ToString() >"500")
{
property.Cancel=true;
property.ErrorMessage ="Any amout greater than 500 cannot be deleted" ;
}
}

In this case when user tries to delete any item whose Amount is greater than 500 gets an error message .

Now as we have done with the Event assembly the next task is to register the assembly.In my next Blog we can check out the registering of events to a list.

Gray Failures: What is it and how to detect one?

If you are reading this article , i guess you are curious to know about gray failures and different methods to detect gray failures.  Hopefu...