Hi All,

 

Last week I finish my SharePoint Server 2007 course and I got a few
issues regarding event handler and DataSheet Views when updating values
in List. 

 

The normal approach to update values is using the ItemUpdated event
using the below code:

 

        public override void ItemUpdated(SPItemEventProperties
properties)

        {

           this.DisableEventFiring();

 

            if ((bool)properties.ListItem["BookOut"] == false)

            {

                properties.ListItem["Person"] = "";

            }

            properties.ListItem.Update();

 

            this.EnableEventFiring();

        }

 

This approach works perfectly when using the Standard View, but if a
user creates a Data Sheet view that is base on an ActiveX control two
problems appear. Firstly the update is not reflected immediately and
secondly if the user tries to change the same row again a conflict sing
appears say that the record has been changed by another user.

 

The first issue is because the ActiveX control is not refreshed once the
update is completed. Even if you can see that the control is waiting for
the asynchronous event to complete to remove the double arrow form the
row. Microsoft could improve this behaviour in the future but at the
moment it is the way it is.

 

The second issue happened because the data in the client is out of sink
as the values has been changed in the database but not reflected in the
font end.

 

At this point I came with two different approaches. One disables the
creation of DataSheet Views (SOLUTION 2) and the other find out a
different way to change values that the ActiveX control will refresh
properly (SOLUTION 1).

 

After two days of trying and near to give up on find a different way to
update the values that will work for the ActiveX control I finally found
the solution. 

 

My first inclination was to use the ItemUpdating event that was
synchronous and happened before the changes are sent to the database.
But I could not find the way to access the changed values in the
ItemList property that was the most obvious place to look. Until I found
a reference in internet to the  AfterProperties property in the
properties object:

 

SOLUTION 1:

 

        public override void ItemUpdating(SPItemEventProperties
properties)

        {

            try

            {

                // DataSheet View return "0" while Standard View return
"False" for boolean fields

                if
(properties.AfterProperties["BookOut"].ToString().CompareTo("0") == 0 ||

 
properties.AfterProperties["BookOut"].ToString().CompareTo("False") ==
0)

                {

                    properties.AfterProperties["Person"] = "";

                }

            }

            catch (Exception ex)

            {

 

                properties.Cancel = true;

                properties.ErrorMessage = string.Format("Error {0}{1}",
Environment.NewLine, ex.Message);

 

                // Redirect to other page if required

                //context.Response.Redirect("/_layouts/MyErrors.aspx");

            }

        }

 

 

Also using this system allows me to show an error message to the user if
something goes wrong. My personal conclusion is that is better practice
to use the ItemUpdating for validation and changes on the same row while
the ItemUpdated can be used for long running process.

 

Also mention that I also found on internet a method to redirect to a
customize error page. I have not fully tested it but to use it you need
to add a reference to the System.Web namespace and the following code to
the start of the event handler class:

 

    public class EventReceiverItemEventReceiver : SPItemEventReceiver

    {

 

        HttpContext context;

 

        /// <summary>

        /// Initializes a new instance of the
Microsoft.SharePoint.SPItemEventReceiver class.

        /// </summary>

        public EventReceiverItemEventReceiver()

        {

            context = HttpContext.Current;

        }

 

     .....

     .....

 

     }

 

Once I finished with this alternative I started to investigate the
option of disable the creation of the Data Sheet Views for a specific
list. The first think I did was asked my teacher if was an option to
disable the creation of Data Sheet via configuration. 

 

He kindly replies to me with a way to hide the link adding some code in
the Core.css file:

 

#diidEditInGrid***on

 

{

 

visibility: hidden;

 

}

 

I did not try this option as was obvious that this option will affect
all the lists in the SharePoint Installation. But it gave me an idea
where to look at.

 

SOLUTION 2 

 

I have found the solution to my problem looking into the viewtype.aspx
page in the layout folder that shows the available views for a specific
list.

 

http://spvm/_layouts/ViewType.aspx?List=%7BEB8B005F%2D9FA3%2D4B4A%2DBFEC
%2D20900315C35D%7D&Source=http%253A%252F%252Fspvm%252FLists%252FABC%252F
AllItems%252Easpx

 

if you add the following code at the end of the onload event in the
ViewType.aspx page code in line then the DataSheet View option will be
disable only for this list.

 

    if
(spList.ID.ToString().ToUpper().CompareTo("EB8B005F-9FA3-4B4A-BFEC-20900
315C35D") == 0)

    {

        fHideGridViewOption = true;

    }

 

You can get the list ID form the list value in string query removing the
%7B and replacing the %2D for a "-".

 

The only issue with this approach is that you have to be careful when
installing SP from Microsoft as this file can be overwritten by the
update.

 

I hope this is of interest for any of you. I will be looking forward for
any feed back. Good or bad.

 

Best Regards,

 

Javier Martinez

 

 



This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.




------------------------------------------------------------------- OzMOSS.com 
- to unsubscribe from this list, send a message back to the list with 
'unsubscribe' as the subject.

Powered by mailenable.com

Reply via email to