I've made a EventReceiver that i want to attach to my Pages library. It will create a folder on a given Image Library for event pictures.

I can say on the elements.xml of the EventReceiver the list that i want to attach it to, using the statement

<Receivers ListTemplateId="850" ListUrl="Events/Pages">

The thing is, this solution will probably be installed on multiple SharePoint sites with different languages, and since the Pages library is created when my Publishing feature is activated, the name of the library will be different for each language, in Portugue it'll be Paginas, in english it'll be Pages.

Is there a way to attach it to the library according to the language my sharepoint is using??

Thank you.


You best bet would be to use a programmatic approach, as Paul suggested. That way, by adding the receiver directly on the SPEventReceiverDefinitionCollection from the EventReceivers property on an SPList object. Just notice that since you added your receiver programmatically you will need to perform manual cleanup too.

I also would point out that AFAIK you should be able to do the same with a caml only declaration by referencing the resource SharePoint uses for the page library name.

<UrlAction Url="$Resources:osrvcore,List_Pages_UrlName;/SomePage.aspx" />

This example is taken from one of my old questions. In this case I am setting the UrlAction url but you should be able to use this format even with the ListUrl. There is a big problem though. This sample does not play well with the MUI support: SharePoint will resolve the url based on the UI culture and not the original site culture. That means that if the site has been created in English, the page lib will be Pages: now if you use the MUI support to show the site in Portuguese, SharePoint will resolve the resource as Paginas, thus creating problems in your custom action. As I said, this is based on my experience with the urlaction param, but I would expect that ListUrl behaves the same. My advice: use code.

(note: If use a code only approach, please accept Paul answer. I am posting this only to leave a reference of the MUI problem - Would have used comments but it is a bit long as you see)

  • Thanks a lot Arch, i'll do some testing with the ListUrl and MUI and see what happens. – C. Hoffmann Mar 19 '13 at 13:55
  • Hoffmann. If you use the resource and it won't give you problems feel free to accept this answer. But if you will use the programmatic approach please consider selecting Paul answer: it has been posted before and contains the same info, so it is more appropriate to reward his answer first. – SPArcheon Mar 19 '13 at 14:01
SPWeb web = properties.Feature.Parent
Guid pagesLibraryId = Microsoft.SharePoint.Publishing.PublishingWeb.GetPagesListId(web);
SPList pagesLibrary = web.Lists[pagesLibraryId];
pagesLibrary.Receivers.Add( ... )

Obviously, you will need to add error checking.

  • Thanks Paul. That'll come in handy if the CAML approach proves inefficient. – C. Hoffmann Mar 19 '13 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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