Tag Info

Hot answers tagged

14

The blog post James's colleague wrote is wrong. If you follow the link he uses you'll see the table for lists he uses is different from the one he references. I use these rules of thumb not to have to look at that post all the time: Never use BeforeProperties. Use properties.ListItem. The properties.ListItem will act as BeforeProperties in an '-ing' ...


10

So, after a few weeks on and off trying to figure this one out, having no luck with any replies on any forum, I just thought I would have a look at how the UI page was doing this. (Why didn't I think of this earlier?!) That's when the property EnableMetadataPromotion showed up. Having this keyword to search for, it didn't take me long to google the missing ...


10

We faced the same problem at work recently. And there are two good options here we've found: 1. Global variable Use SPWeb.Properties or some other SharePoint property bag, and use kind of "global variable" trick: you set this variable to "ON" before the batch is executed, and set it to "OFF" later when the batch is finished. And in your event receivers, ...


9

You're seeing this because RunWithElevated runs the code under the AppPool account of the current web application, but the SPWebApplication itself is stored in the config database, which is handled by a different account (the farm account). You will have to run this Feature at Farm scope in order for it to be able to write to the config database.


8

When scoped to site it fired for all lists. When I scoped the solution to web it worked. Hope it helps. -Padeep Nulu


8

You have to register the ItemAdded event as Synchronous event. SPEventReceiverSynchronization.Synchronous You can define it programmatically: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverdefinition.synchronization.aspx Or in the Receiver element of the feature definition: http://msdn.microsoft.com/en-us/library/ff512765.aspx


8

Both mean the same; handle the Event or receive the event.


8

With the help of MS support, we finally got to the bottom of this issue. It turned out to be related to the content database upgrade (from MOSS 2007 to 2010) that had taken place months before. Ultimately, there was no object model fix for the problem, and the SharePoint product group ended up giving us permission (and code) to modify the content database ...


8

You can use this approach - create class: public class DisabledItemEventsScope : SPItemEventReceiver, IDisposable { private readonly bool oldValue; public DisabledItemEventsScope() { oldValue = EventFiringEnabled; EventFiringEnabled = false; } #region IDisposable Members public void Dispose() { ...


7

If the feature scope is set to Site, then the ListUrl and the ListTemplateId is ignored, and then it will fire on all events for all lists. Fix it by putting your eventreceiver in a web-scoped feature.


7

Going back to WSS2/SP2003 it was Event Handler. With WSS3/SP2007 it changed to Event Receiver...there is even a setting on the Web App in CA that let's you enable/disable support for backwards-compatible event handling. In the context of 2010, "event handler" or "event receiver" is one in the same.


7

Form MSDN : SPEventReceiverBase.DisableEventFiring Method Prevents events from being raised. So someone could think that all events are disabled (all items, all events, all receivers). But: How DisableEventFiring / EventFiringEnabled works The setting (DisableEventFiring in 2007 and EventFiringEnabled in 2010) must be for the current event ...


6

It is not possible to add event handlers to the user info list. Please see this following thread: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/81aae5ef-9621-48c5-ad52-706e5d6a0f05 That was me asking the question.


6

I had the same problem, and debugged for literally weeks. The solution I ended up with was deleting the elements.xml file that specifies the target of the event receivers, and binding the event receivers to your lists programmatically in the FeatureActivated (and don't forget to detach them in FeatureDeactivating). Hope this helps someone.


6

I anticipate that your root list has the same event receiver assigned to it, and that causes the recursion. The problem, of course, may be not so obvious, but anyway, to prevent event receiver to fire several times, there is a common practice in SharePoint: just use DisableEventFiring and EnableEventFiring methods. internal void ...


6

With SP2010, You can use ItemAdded with Synchronization (instead of ItemAdding) to perform some operations after the item is created but before it is presented to the user. Then you can use if(properties.ListItem.File!=null)to determine if listitem has file associated with it. To make ItemAdded synchronous, you need to set the Synchronization property ...


6

Usually in Page_Load or in CreateChildControls you should place the check for IsPostback and load the data only if the page is not in the postback mode. And also, you should load the data in all postback handlers. This way, the data is loaded always and only once per page load. But while this solution will work perfectly for a separated page, things get ...


5

From TechNet, the issue is that using Inherits="TRUE" in the content type definition will ignore XmlDocuments. You must use Inherits="FALSE" and manually add the fields to be inherited.


5

Since you are using ItemAdded in SharePoint 2007 that event is asynchronous and happening after the item is added. Asynchronous means that it will happen "behind the scenes", ie you cant redirect the user to an error page. Instead try to use the ItemAdding if you need to cancel the event and present an error message for the user.


5

You can check the TemplateFeatureId property of the SPList object, to see which feature the list template belongs to. The AssetLibrary feature has ID={4BCCCD62-DCAF-46dc-A7D4-E38277EF33F4} . In a Team Site on the other hand the "Site Assets" is created as a document library in code, using the same template feature as "Shared Documents" ...


5

You might be able to differentiate by knowing Content Type of the item being added. You can get Content Type by accessing properties.AfterProperties["ContentTypeId"] As documented here, Document Content Type ID starts with 0x0101 vs Folder's content type id - 0x0120 So your code may look like: SPContentTypeId itemContentType = new ...


5

You have to do following: properties.RedirectUrl = properties.Web.ServerRelativeUrl + "/_layouts/settings.aspx"; properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl; properties.Cancel = true; Or properties.ErrorMessage = "File extension not allowed here"; properties.Status = SPEventReceiverStatus.CancelWithError; ...


5

Your discussion intrigued me and I decided to test it eventually :) I wrote 4 event receivers - ReceiverS1, ReceiverS2, ReceiverA1, ReceiverA2, sync (seq num 100), sync (seq num 101), async (seq num 100), async (seq num 101) accordingly. I added receivers and verified using sharepoint manager that all settings correct. This is code for receivers: ...


5

Ouch! Are you trying to use Word Interop in an event receiver! You should not! This will instantiate Word (the actual application) on the server side and this is a really scary and bad operation! Just don't do it! It's not even supported, but that's not the issue here - you server will eventually fail miserably... Now, on to how to do it! Converting from ...


5

I've always had to handle the concurrency issues. On SP 2010, I've done these things: 1) Set the Synchronization property of your receiver to SPEventReceiverSynchronization.Synchronous. 2) Disable event firing within the receiver methods e.g. this.EventFiringEnabled = false; 3) When working with Properties.ListItem object, check if it's not null before ...


5

Might want to take a look at this article http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverbase.disableeventfiring(v=office.12).aspx Basically, what your looking for is something like this base.DisableEventFiring(); item.update(); base.EnableEventFiring();


5

You basically have to create a custom SPWebEventReceiver and activate your mandatory feature under "WebProvisioned" method, like this: public class YourWebEventReceiver : SPWebEventReceiver { public override void WebProvisioned(SPWebEventProperties properties) { base.WebProvisioned(properties); // Activate your ...


5

welcome to SharePoint Stack Exchange!! It is not possible out of the box, just so that you know! But, your problem was so interesting that I thought of spending couple of hours just to develop a small customization :) So this is how my solution works: The default size of images posted on Newsfeed time-line is 300x300px I developed a custom feature that ...


4

Are you intentionally using the asynchronous (after) event? I would suspect that displaying an error message would work better if you would override the ItemCheckingOut event instead.


4

There is no need to create a new SPSite object. Instead use: properties.Web.Site



Only top voted, non community-wiki answers of a minimum length are eligible