Home » Sharepoint 2010

Disable Event (ItemUpdated) with powershell


I'm trying to update an item in a list without firing the ItemUpdated-Event. In SP2007 this was possible with EnableEventFiring () and DisableEventFiring() - now MSDN says its obsolete. I'm wondering if there is a way to disable Events from powershell for an update? Any hints for me?


Cheers and thanks for your time!



1 Answer Found


Answer 1

Hi MaxMelcher,


As what you said, the “EnableEventFiring” is obsolete  for sharepoint 2010. I don’t know if there is a way to enable it using PowerShell. But Sharepoint 2010 has created a new property “EventFiringEnabled” to replace the “EnableEventFiring” method.


More information about “EventFiringEnabled



Also here is an article about toggling events, I think it’s helpful to you.




In a ItemUpdated event on a list i normally i use "properties.ListItem" to get data before the changes, and "properties.AfterProperties" to get data after the chages

But when working with document libraries things get a lot complicated. The ItemAdded handler gets called when a file is uploaded, not when the user specifies it's metadata. To handle these metadata i have to use the ItemUpdated handler.
But even there it happens that "properties.ListItem" and "properties.AfterProperties" result both null, so i cannot access any data i need

Is there a way to get a document metadata when it is added to a library?


I have a document library that's used to store contracts on a SharePoint 2007 site. When the user uploads the contract (in PDF format), they must enter in a Contract ID (chosen from a BDC entity). Once they assign it a Contract ID, the system changes the filename of the PDF file to the contract ID. So if the pdf is ABC.pdf and they choose contract ID "123", SharePoint moves the file to the new URL (based upon the contract ID). I tested it and it was working for me without issue, but now we're getting the following error when checking in the document:

"The URL '/VendorContract/ABC.pdf' is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web."

When I go back into my document library, I see the item in the doc lib, and it's renamed, but it's still designated as checked out. I can check the file back in and it seems to function correctly. I able to successfully upload some files, but not others.

I am using the ItemUpdated method on the library. Here is the code that I'm using:

Dim Item As SPListItem
    Dim file As SPFile
    Dim newurl AsStringDim Contractid AsString, PrevContractid AsStringDim conn_BRT As SqlConnection, cmd As SqlCommand
    Dim sqltype AsString

    Item = properties.ListItem
    file = Item.File
    PrevContractid = properties.BeforeProperties("Contract")
    Contractid = properties.AfterProperties("Contract")
    newurl = "VendorContracts/" & Contractid & ".pdf"


Like I said, I am able to upload some documents without issues, but once a document fails, it will always fail.

Any suggestions?

Thanks in advance,



Hello all,

So, to sum is up, I have a FormView:

        <asp:FormView ID="fvSubscriptionEdit" DefaultMode="Edit" runat="server" GridLines="None"
            CssClass="SubEditPanel" OnItemUpdating="fvSubscriptionEdit_ItemUpdating">
                    Abonnement wijzigen</h2>
                <asp:HiddenField runat="server" ID="hfSubscriptionId" Value='<%# Bind("SubscriptionId")%>' />
                <asp:Label runat="server">Type wijzigen</asp:Label>
                <asp:DropDownList ID="ddlTypeEdit" runat="server" SelectedValue='<%# Bind("SubscriptionType")%>'>
                    <asp:ListItem Text="- Kies -" Value="1" />
                    <asp:ListItem Text="Upgrade" Value="upgrade" />
                    <asp:ListItem Text="Verlengen" Value="verlengen" />
                <hr />
                    Credits wijzigen</h2>
                <asp:Label runat="server">Nieuw aantal credits</asp:Label>
                <asp:TextBox ID="txtCreditsEdit" runat="server" Text='<%# Bind("SMSCredits")%>' />
                <div class="optionbox">
                    <asp:LinkButton ID="lbUpdateSubscription" CommandName="Update" CssClass="submit"
                        Text="Opslaan" runat="server" />

And the relevant code:

    protected void fvSubscriptionEdit_ItemUpdating(object sender, FormViewUpdateEventArgs e)
        SubscriptionService subService = new SubscriptionService();
        Subscription sub = subService.get(Convert.ToInt32(e.NewValues["SubscriptionId"]));

        if (!string.IsNullOrEmpty(e.NewValues["txtCreditsEdit"].ToString()))
            sub.SMSCredits = Convert.ToInt32(e.NewValues["txtCreditsEdit"]);

        if (!string.IsNullOrEmpty(e.NewValues["SubscriptionType"].ToString()))
            //Upgrade | Prolong
            switch (e.NewValues["SubscriptionType"].ToString())
                case "upgrade":
                    sub.BeginDate = DateTime.UtcNow;
                case "verleng":
                    sub.BeginDate = sub.EndDate;

            sub.EndDate = sub.BeginDate.Value.AddYears(1);


What does work: I do see the right info if the formview is shown but when I click on the Update button it just doesnt fire the corresponding itemupdating event.

Can someone see what is wrong or missing?

What do I want to archieve: Just update the subscription's credits and its type: Upgrade, Prolong. If there is a  more simpler method, please do tell :)


New finding: I added 'onitemcommand="fvSubscriptionEdit_ItemCommand"' to the formview and a corresponding event method with a simple code that throw a exception(just testing) but it doesnt enter the method but does whine when the method is missing. So why does it whine if the method is not there but doesnt enter the method if it does exist? I presume that this is the same problem.





I have 2 Details Views. Each Details View has its own Update function.
How can I call/execute the 2nd Details View update event when I click on Update Button of 1st Details View?

Protected Sub DetailsView_1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventA rgs) Handles DetailsView_1.ItemUpdated
'To call DetailsView_2_ItemUpdated event here ...
End Sub

Protected Sub DetailsView_2_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventA rgs) Handles DetailsView_2.ItemUpdated
'To call DetailsView_1_ItemUpdated event here ...
End Sub 


I have a very simple ItemUpdating event handler that is causing an SPRequest object was not disposed error when it is fired. The event handler is linked to the document library. I have cleaned out all of my code and narrowed it down to this:

publicoverridevoid ItemUpdating(SPItemEventProperties properties)
      SPListItem item = properties.ListItem;

When I change the name of a file or folder in my document list the following line is logged in the SP log:

An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  This object will now be disposed.  Allocation Id: {D7AA6805-4CA1-458B-9252-E83D32DBD0D3}  To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true.


As an extra note I have actually set the CollectSPRequestAllocationCallStacks to true, this is all the information that it gives me. If I comment out the properties.ListItem line then the error is not logged so I am sure it is this line that is causing the problem. Anyone have any ideas. Also, in case someone asks, yes I have run SPDisposeCheck on my code. It returns no errors or problems.



how to get attachements in ItemUpdating event?

i am trying to get all attachments in ItemUpdating event. here is my code.

  private HttpContext hContext = null;

        public BeforeCustomListItemAdding() : base()
            hContext = HttpContext.Current;

 public override void ItemUpdating(SPItemEventProperties properties)
     using (SPSite currentSite = new SPSite(properties.SiteId))
               using (SPWeb currentWeb = currentSite.OpenWeb(properties.RelativeWebUrl))

         SPList list = currentWeb.Lists[properties.ListId];

                   if (list.Title.ToLower() == "testlist")
             if (hContext != null)
                           if (hContext.Request.Files.Count > 0)



i am not getting any attachment in it.

i do know where i am wrong. pls help me.



Is there a way to know which item has been updated (and which are the updates) in a ItemUpdating event handler?

I was trying with this code:

      SPItemEventDataCollection before = properties.BeforeProperties;
      Hashtable table = before.ChangedProperties;
      ICollection collection = table.Keys;
      foreach (string str in collection)
        String prova = str + ": " + table[str];

but my collection results empty after the updating of some fields

Any idea about it?



     I have custom field which has to be updated with a value when the project cost changes its value. Is there any Event Handler to manage this or any other option where I can resolve the solution.




I´m using Sharepoint 2007 and Infopath 2007.

I have created a event receiver to handle the ItemUpdated event.

I´m using Enable/Disable event firing, "Required Check out to be edited" is disabled.

I have checked if it´s subscribed twice for the same event receiver and it´s not.

The event (ItemUpdated) get fired twice when I submit it from InfoPath. If I upload the infopath document (.XML) it doesn´t fire twice.

I have looked all over the internet and couldn´t find a solution for it.

Any help is very appreciated.

Hugo Leonardo Scaramal

I have created a ItemUpdate Event Handler which saves data to a custom list on top level site when a document library List Item version updates. Now I need to implement this event handler to apply on whole document libraries which reside in Web Application, Site Collection, Sites & Sub-sites. Using recursive programming that event handler must be applied to every document library. Can any one help me with a sample code snippet?



I would appreciate if someone help me to understand this situation. I do not know why but when i edit selected ListView item (containing few TextBoxes) and then press Update button in the ItemUpdating event i always get old values instead of those which were typed recently. Why?

I do not use Page_Load event so i do not need check on PostBack I try to get value before i bind data from DB to ListView, so it can't override recently typed values I tried to get TextBoxes values in different Event handlers - ItemCommand, ItemUpdating, ItemDataBound - result si always the same Collection NewValues and OldValues are always empty (i think this is because i don't use SqlDataSource control) The only one way i can get new values - is to check Request, but in this case i can't use control validators ... so probably it is bad idea to work with only request.

This is the code of ItemUpdating method:


ListViewItem editItem = AdminUsersListView.EditItem;
Guid userId = new Guid((editItem.FindControl("UserId") as HiddenField).Value);
Hashtable dataUpdate = new Hashtable
          { "UserName", Request[ (editItem.FindControl("UserNameNew") as TextBox).UniqueID ] },
          { "Email", Request[ (editItem.FindControl("Email") as TextBox).UniqueID ] },
          { "IsApproved", Request[ (editItem.FindControl("IsApproved") as CheckBox).UniqueID ] == "on" },
          { "IsLockedOut", Request[ (editItem.FindControl("IsLockedOut") as CheckBox).UniqueID ] == "on" }

var x1 = dataUpdate["UserName"]; // this is corrent new value from Request
var x2 = (editItem.FindControl("UserNameNew") as TextBox).Text; // this is WRONG! OLD! value from TextBox ... Why???

using (Entities entities = new Entities())
          aspnet_Membership membershipItem = entities.aspnet_Membership.Where(MBS => MBS.UserId == userId).FirstOrDefault();
          membershipItem.Email = dataUpdate["Email"].ToString();
          membershipItem.LoweredEmail = membershipItem.Email.ToLower();
          membershipItem.IsApproved = Convert.ToBoolean(dataUpdate["IsApproved"]);
          membershipItem.IsLockedOut = Convert.ToBoolean(dataUpdate["IsLockedOut"]);
          aspnet_Users userItem = entities.aspnet_Users.Where(USR => USR.UserId == userId).FirstOrDefault();
          userItem.UserName = dataUpdate["UserName"].ToString();
          userItem.LoweredUserName = userItem.UserName.ToLower();

AdminUsersListView.EditIndex = -1;
AdminUsersListView.DataSource = _getDataList();


Thanks, Art

I'm looking to disable certain site templates available to users via the "create site" menu and would like to just do it for one entire web application, but not the whole farm. Is there a way to do this via powershell? (It honestly baffles me that this still isn't a UI control via central admin)

 I have event handler onPublish project server 2010. It need to check out modify and publish project. So donnot want to have infinit loop here. I see share point has this.disableeventfiring but does project server?




Hello everyone. When I try to execute the following Powershell code from a SQL job step, I get an error. When I execute it on my own machine from a Powershell prompt there is no error.


Executed as user: DCCORE\dccoreSvcAcctSQLSvr. A job step received an error at line 5 in a PowerShell script. The corresponding line is '$Conn = new-object System.Data.OleDb.OleDbConnection $ConnString'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Exception calling ".ctor" with "1" argument(s): "An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'."  An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'.  '.  Process Exit Code -1.  The step failed.


My Powershell Code:

$ConnString = "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=\\care1\is\production\projects\one time\map projects\ncqa_51206\Data\Member;"
$query = "select [*] from [Member_51206.DBF]"

$Conn = new-object System.Data.OleDb.OleDbConnection $ConnString

$cmd = new-object System.Data.OleDb.OleDbCommand $query,$Conn

$da = new-object System.Data.OleDb.OleDbDataAdapter $cmd
$dt = new-object System.Data.dataTable 
$connectionString = "Data Source=ratEtl;Integrated Security=true;Initial Catalog=coEtl;"
$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $connectionString
$bulkCopy.DestinationTableName = "Member51206"


Im working on a multitouch wpf aplication, everytime mouse is moved block multitouch events.

Is possible disable mouse events on wpf multitouch appz?

Just only on the appz not in all windows OS
I think the asswer is no, but apreciate any coment.

I no want disable mouse at OS level, just make my aplication no catch Mouse events.

I enabled Windows Events for OnError, OnTaskFailed, OnWarning for my package and subelements.  However, even if no errors occur, I still get Informational Events generated even though those are disabled for all modules and packages. 

Any way to disable Information Events?  Is this an SSIS defect, or just an oddity of how it implements Windows Events?

Windows Event:
Source: SQLISPackage
Type: Information
Event ID: 12288
Description: Package "XXXXXX" started.

Event ID: 122289
Description: Package "XXXXXX" finished successfully.

Hi There,

I ran into some event provider disable issue days ago.

I am using SQL 2005 with Notification services. We have one application with six event providers. It work fine before but recently,

1) some of the providers get disabled by itself. I enable all of them but they get disabled again later.
2) I find some errors in event log (application). I believe there is some relation between them.

Source: NotificationServices

Event ID: 2026

Description: The event provider did not return from its Run method within the specified timeout period.


  Provider Name: Rule6

InstanceName: 123

ApplicationName: EmailAPP

Component: Event provider host

Thread: 13

Source: NotificationServices

Event ID: 2026

Notification Services is terminating the event provider because it returned an error from its Run method.


  Provider Name: Rule6

InstanceName: 123

ApplicationName: EmailAPP

Component: Event provider host

Thread: 13

Source: NotificationServices

Event ID: 2990

Description: The SQLProvider event provider failed to submit a batch.


  Provider Name: Rule6

  Event Class Name: Rule6_ev

Description: Thread was being aborted.

InstanceName: 123

ApplicationName: EmailAPP

Component: Event collection

Thread: 18

Please give some advices on how to solve this problem. ( maybe the timeout error is the key? I am not sure)




Hi guys,

I used textbox.leave so that when user leave the textbox, it will fire a function.

Under some cases, I would like to disable this textbox.leave event.

Please let me know if there is anyway to do this.



Hi there,

Is there anyway of disabling the All day Event field in a Calendar list. I don't have the option to hide it either.


Hai i'm developing windows application using vb.net. I have to use waiting cursor for processing some items,at that time users are not allowed to access the other things in the form. I set the waiting cursor but it allows the user to access the other links. So i want to disable the mouse events after the processing complete then enable the mouse events. Please give me the solution or give any other ideas to do this work.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure