Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have having a situation where I have an event receiver that uses ItemUpdated event to automatically start workflow. This is causing problem when user clicks on Edit in Excel and check in items from there. Code to redirect to workflow start form is executed but since excel uses /_vti_bin/List.asmx, it raises error.

Is there any way I can detect if item is updated through UI or through service?

Thanks in advance

share|improve this question

2 Answers 2

I am able to resolve this problem. Here is how:

Add a variable to store SPContext in event receiver and assign it in constructor:

SPContext currentSPContext;

//#ctor
public ClassName()
{
  currentSPContext = SPContext.Current;
}

If source updates data from service you will get referrer null. You can check it by using:

currentSPContext.Request.ServerVariables["HTTP_REFERRER"]

Chears!

share|improve this answer

You should check the user who is performing the action in item updating and set a value. If it is the service account or not.

You want to reference:

properties.CurrentUserId;

This only works for before events (Ending with a ing basically Adding, Deleting etc...)

You can't get the user from Updated.

But if the library is updated the modifiedby will be set to the value of that user, but this can perhaps not be the case for if example you have another event receiver running, it will set as the app pool account or something similar.

Hope this helps.

share|improve this answer
    
Thanks for the help, this isn't working as expected –  Prashant Lakhlani Oct 31 '12 at 8:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.