Hi All,

 

Regarding this thread, if any on is interested. I have found out the
following regarding this code:

 

public class ItemEventReceiver : SPItemEventReceiver

    {

 

        private SPContext CurrentContext;

        private SPViewContext CurrentViewContext;

 

        private String ViewID = "";

 

        /// <summary>

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

        /// </summary>

        public ItemEventReceiver()

        {

            if (SPContext.Current != null)

            {

                CurrentContext = SPContext.Current;

                CurrentViewContext = CurrentContext.ViewContext;

                //ViewType =
CurrentContext.List.Views[CurrentViewContext.ViewId].Type;

                ViewID = CurrentViewContext.ViewId.ToString();

           }

        }

 

...   

 

        public override void ItemUpdating(SPItemEventProperties
properties)

        {

            properties.AfterProperties["Title"] = ViewType;

        }

    }

 

 

1)       The View property is null in the SPViewContext object when
using Data Sheet View. But returns an exception when using Standard View
('CurrentViewContext.View' threw an exception of type
'System.ArgumentException').

2)       The ViewId is {00000000-0000-0000-0000-000000000000} in
theSPViewContext object when using Data Sheet View. But returns
{7a7621b6-7892-4d6a-bc3f-7a7365b786a6} when using Standard View that
looks a good one.

3)       If I try to get the view using the ViewId returned in the
Standar View using this code
"CurrentContext.List.Views[CurrentViewContext.ViewId].Type;" I get the
same exception that in the step one.

 

I guess that for some reason the SPConext.Current is not able to get the
current View when using the ActiveX control and when using html standard
view, it is getting the wrong ID maybe because the ItemUdating event is
fired when the page is in the edit page. I think here is more TODO work
for Microsoft.

 

For my porpoise I can use the ViewId to figure out what type of view I
am on. But will be nice to have the proper value returned from the
object. 

 

One thing I would like to ask. Is possible to add additional event
handlers to the SPItemEventReceiver? What I was thinking of is to catch
the beginEditing event of a list and see if there the SPContext object
has the correct values there. 

 

Thanks / Regards,

 

Javier

 

 

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Martinez, Javier (Outsourcing)
Sent: Tuesday, 25 November 2008 11:22 AM
To: listserver@ozMOSS.com
Subject: RE: [OzMOSS] RE: Getting the current view of a list in the
updating event handler.

 

Hi Ishai,

 

Thanks for you reply. Your answer was not what I was hopping but gives
me an idea of a way to try and I do not give up until I try my last
idea.

 

I remember reading on internet a way to get the current http context
adding the following lines in the initialization of the class:

 

using System.Web;

 

namespace SoftwareRegisterList

{

    public class ItemEventReceiver : SPItemEventReceiver

    {

        HttpContext CurrentHttpContext;

 

        public ItemEventReceiver()

        {

            CurrentHttpContext = HttpContext.Current;

        }

...

}

 

Yes, but the HttpContext do no have any reference to the SPView. Then I
check the SPContext and I found that has a ViewContext property that
return a SPViewContext object that contain an View property that return
an SPView object.

 

Then, I tried to use the same code but changing the HttpContext to
SPConext like this:

 

public class SoftwareRegisterEventReceiverItemEventReceiver :
SPItemEventReceiver

    {

        SPContext CurrentContext;

 

        public SoftwareRegisterEventReceiverItemEventReceiver()

        {

            CurrentContext = SPContext.Current;

        }

 

And yes, I get the SP Current Context but for my desperation the
ViewContext property is not instantiated. Then I saw that was a
CurrenContext method in the  SPItemEventReceiver class. But again no
luck and here is my first question:

 

Why is an overridden CurrentContext method created when you add an event
handler if this method does not exist in the SPItemEventReceiver Class
at all and then it will never fire? I suppose the answer is the TODO
summary description on the top. :o)

 

At this point I am running out ideas but I would like to ask if you or
any in the news group has tried this path and what was the outcome.

 

Best Regards,

 

Javier Martinez

________________________________

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Ishai Sagi
Sent: Monday, 24 November 2008 3:35 PM
To: listserver@ozMOSS.com
Subject: [OzMOSS] RE: Getting the current view of a list in the updating
event handler.

 

You cant. Even though the event is synchronous, you don't get a
reference to the current context, which means you will not be able to
tell.

 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Martinez, Javier (Outsourcing)
Sent: Monday, 24 November 2008 5:03 PM
To: listserver@ozmoss.com
Subject: [OzMOSS] Getting the current view of a list in the updating
event handler.

 

Hi All,

 

I have been trying to figure out how to get the current view of a list
in the updating event handler but no luck. My problem is that I want to
know if the view is Standard or Grid and do different things depending
on the view. Something like this:

 

        /// <summary>

        /// Synchronous before event that occurs when an existing item
is changed, for example, when the user changes data in one or more
fields.

        /// </summary>

        /// <param name="properties">

        /// A Microsoft.SharePoint.SPItemEventProperties object that
represents properties of the event handler.

        /// </param>

        public override void ItemUpdating(SPItemEventProperties
properties)

        {

            if
(string.IsNullOrEmpty((string)properties.AfterProperties["Person"]) ==
true)

            {

                if
(string.IsNullOrEmpty((string)properties.AfterProperties["Return Date"])
== true)

                {

 
if(GetCurrentViewType(properties.ListItem.ParentList).CompareTo("GRID")
== 0)

                    {

                        properties.AfterProperties["Book out"] = 0;

                    }

                    else

                    {

                        properties.AfterProperties["Book out"] = false;

                    }

                }

            }

        }

 

        public string GetCurrentViewType(SPList List)

        {

            foreach (SPView View in List.Views)

            {

                // This does not work when the List is embedded in a
webPart

                if (View.Url.CompareTo(List.ParentWebUrl) == 0)

                {

                    return View.Type;

                }

            }

 

            return "N/A";

        }

 

I have tried to use the parameters.ItemList.ParentList object with the
GetView, Views and DefaultView properties but any of them return the
view used in the current context. Any help will be appreciated.

 

Regards,

 

Javier


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 


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
-------------------------------------------------------------------
OzMOSS.com - to unsubscribe from this list, send a message back to the
list with 'unsubscribe' as the subject.
Powered by mailenable.com


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