I'm trying to create a feature to register my event handler to a specific list. I'm building it like I would a normal feature. However, I'm not sure how to define my Elements file. The file for my feature is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="101">
<Receiver>
<Name>AddedEventHandler</Name>
<Type>ItemAdded</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>ChangeContentTypeEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7bfc7c17f98031d7</Assembly>
<Class>ChangeContentTypeEventHandler.ChangeContentTypeEventHandler</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
</Receivers>
</Elements>
Based on this, how would I set up the file for registration of this event handler?
Also, here is my Feature.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Scope="Web" Title="Change Content Type Event Handler"
Id="{27C2FDFF-ADA0-4984-955C-6448E182FA88}"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ListTemplates\ListManifest.xml"/>
<ElementFile Location="Messages\schema.xml"/>
</ElementManifests>
</Feature>
Also, can this be part my solution package WSP for the feature itself so that it gets deployed with the feature?
Thanks in advance
You have two options here. Either you create a custom list template so that you can specify the id of your custom list template in your elements file, or you have to attach your event receiver through code (feature receiver).
The problem with registering an event receiver declaratively is that you can only specify the list template id (effecting all lists based on the specified template), but not a single list name or id.
You can find an example of such a feature receiver in this article: http://www.sharepointdev.net/sharepoint--development-programming/whether-there-is-a-way-to-register-a-custom-event-handler-at-a-special-list-63446.shtml
Related
In Hybris Back Office, how do I add another tab in the explorer tree for managing (create, search, delete) instances of some items?
I can't really find anything on the subject.
Do I need to use the already available UI for it or add my own widget?
In your *-backoffice-config.xml file, you have to add something like this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config xmlns="http://www.hybris.com/cockpit/config"
xmlns:y="http://www.hybris.com/cockpit/config/hybris"
xmlns:wz="http://www.hybris.com/cockpitng/config/wizard-config"
xmlns:list-view="http://www.hybris.com/cockpitng/component/listView"
xmlns:editorArea="http://www.hybris.com/cockpitng/component/editorArea"
xmlns:explorer-tree="http://www.hybris.com/cockpitng/config/explorertree"
xmlns:simple-search="http://www.hybris.com/cockpitng/config/simplesearch"
xmlns:advanced-search="http://www.hybris.com/cockpitng/config/advancedsearch"
xmlns:df="http://www.hybris.com/cockpitng/component/dynamicForms"
xmlns:dsb="http://www.hybris.com/cockpitng/config/dashboard"
>
<context merge-by="module" parent="auto" component="explorer-tree">
<explorer-tree:explorer-tree xmlns:explorer-tree="http://www.hybris.com/cockpitng/config/explorertree">
<explorer-tree:navigation-node id="backoffice.myCustomItemType">
<explorer-tree:type-node code="MyCustomItemType" id="MyCustomItemType"/>
</explorer-tree:navigation-node>
</explorer-tree:explorer-tree>
</context>
<context type="MyCustomItemType" component="listview">
<list:list-view xmlns:list="http://www.hybris.com/cockpitng/component/listView">
<list:column qualifier="customAttribute1" />
<list:column qualifier="customAttribute2" />
</list:list-view>
</context>
</config>
Like way, you can configure "editorArea", "advanced-search", "create-wizard" etc by refering any OOTB backoffice-config.xml file.
Find this document for the steps.
I have the following Feature:
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="9A3C5D02-A2EB-4725-97F7-CDA6DE319F1B"
Title="My Custom Types"
Scope="Site"
DefaultResourceFile="core"
Hidden="TRUE"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml" />
<ElementFile Location="templates/MeetingMinutes.docx" />
</ElementManifests>
</Feature>
Which contains the following Elements.xml:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Templates" Url="_cts/Meeting Minutes" Path="templates" RootWebOnly="TRUE">
<File Url="MeetingMinutes.docx" Type="Ghostable" />
</Module>
<ContentType
ID="0x01010066DD088A6B8B46BCA775CCD119FBB3E8"
Name="Meeting Minutes"
Group="Custom Content Types"
Version="0">
<FieldRefs />
<DocumentTemplate TargetName="MeetingMinutes.docx"/>
</ContentType>
</Elements>
I then use this ContentType within a custom List Template:
<ContentTypes>
<ContentTypeRef ID="0x0101">
<Folder TargetName="Forms/Document" />
</ContentTypeRef>
<ContentTypeRef ID="0x01010066DD088A6B8B46BCA775CCD119FBB3E8">
<Folder TargetName="Forms/Document" />
</ContentTypeRef>
<ContentTypeRef ID="0x0120" />
</ContentTypes>
I deploy the solution, activate the feature, and create an instance of the List Template. I go into the library and select Settings > Document Library Settings > Content Types: Meeting Minutes > Parent: Meeting Minutes > Advanced settings. I'm now in the Advance Settings of the Site Content Type. The URL of the existing document template is MeetingMinutes.docx and there is an (Edit Template) link which points to http://myserver/sites/testsite/_cts/Meeting%20Minutes/MeetingMinutes.docx. Everything's shiny.
But, I hit the back button two times so I'm back in the settings of the List Content Type. This time when I click Advance settings, the URL of the existing document template is still MeetingMinutes.docx, but there is no (Edit Template) link. Troubling.
Pressing on, I go back to AllItems.aspx and click New > Meeting Minutes. As Word is loading, I see a little Opening dialog which says, Opening: http://myserver/sites/testsite/Shared%20Documents/Forms/Document/MeetingMinutes.docx, to which Word responds: "Word was unable to read this document. It may be corrupt."
So the Document Template works correctly in the Site Content Type (where it does me no good), but is not working in the List Content Type (where I really need it). Now, I know I could put this in _layouts, but from what I've read, _cts is the way to do it. What am I doing wrong?
Rich, I'm not exactly sure what's going on because I created a feature using your feature and elements files as you specified and it works correctly for me.
There is one difference though.
When I create a new document in the library from the content type, the template url is
http://myserver/sites/testsite/Shared%20Documents/Forms/Meeting Minutes/MeetingMinutes.docx
Not
http://myserver/sites/testsite/Shared%20Documents/Forms/Document/MeetingMinutes.docx
Somehow your content type seems to be looking in the wrong folder for the template. I hope that gives you some clues.
I had the same exact problem with document template for List Content Type.
What I did is just what SharePoint do when you create your library from web site : duplicate the document template inside the “Forms” folder of the library in a subfolder that have the same name than the content type.
You just need to add a module element somewhere in your project :
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="MeetingMinutesListInstanceTemplate" Url="Shared Documents/Meeting Minutes" Path="templates" RootWebOnly="TRUE">
<File Url="MeetingMinutes.docx" Type="Ghostable" />
</Module>
</Elements>
It worked for me.
I have this feature
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="c54f20d8-1ad1-49b8-aff7-2c874dd2f45a"
Title="MyCompany Content Types"
Description="Content Types required for MyCompany Provided Applications and Functionality"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Site"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="siteColumns.xml"/>
</ElementManifests>
</Feature>
Here is the contents of siteColumns.xml
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
ID="{1F343F02-22D9-45b8-A2A8-CEB2619A28C4}"
Name="AllowSubstDelivery"
DisplayName="AllowSubstDelivery"
Type="Boolean"
Format="TRUE"
Group="MyCustomGroup"
/>
</Elements>
The feature installs and activates, without producing an error, but the siteColumn is nowhere to be found, any ideas why this site column is not visible?
I checked the logs, no errors reported either.
Hmmm... it looks like you have done everything correctly. Did you copy and paste the ID for the Field from anywhere? If so, the ID may already be in use causing your Field provision to be ignored.
I find the best way to create a Feature defining Site Columns and Content Types is to prototype everything using the Web interface and then copy and paste the generated CAML into your Visual Studio projects. I recorded a short video demonstrating the process that you may find valuable.
SharePoint Site Columns and Content Types via a Feature
What does Format="TRUE" mean?
Doesn't look like it's according to documentation.
Field Element Documentation doesn't tell you much about those properties, however there is much in common with FieldRef element and it has documentation about Format attribute.
Maybe you wanted to use DefaultValue attribute?
I have written a feature(Site scoped) that adds custom menu items to the New Menu and EditControlBlock of a SharePoint 2007 document library. These menu items should show up only when the user has add and edit permissions for that document library. This works great except for one particular case where the user has only read permission for the parent site but has full control over the document library. In this case the menu items under EditControlBlock show up correctly but the menu items under New menu do not show up. I have set the same rights for all the menu items. Below are the sample entries in Feature and Element manifest file
<?xml version="1.0" encoding="utf-8" ?>
<Feature
Id="59bba8e7-0cfc-46e3-9285-4597f8085e76"
Title="My Custom Menus"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml" />
</ElementManifests>
</Feature>
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="EditMenu1" RegistrationType="FileType" RegistrationId="txt" Location="EditControlBlock" Sequence="106" ImageUrl="/_layouts/images/PPT16.GIF" Title="My Edit Menu" Rights="AddListItems,EditListItems">
<UrlAction Url="javascript:var surl='{SiteUrl}'; window.location='/test/mypage.aspx?siteurl='+surl+'&itemurl={ItemUrl}&itemid={ItemId}&listid={ListId}&Source='+window.location" />
</CustomAction>
<CustomAction Id="NewMenu1" GroupId="NewMenu" RegistrationType="List" RegistrationId="101" Location="Microsoft.SharePoint.StandardMenu" Sequence="1002" ImageUrl ="/_layouts/images/DOC32.GIF" Title="My New Menu" Rights="AddListItems,EditListItems">
<UrlAction Url="javascript:var surl='{SiteUrl}'; window.location='/test/mypage.aspx?siteurl='+surl+'&listid={ListId}&Source='+window.location" />
</CustomAction>
</Elements>
Am I missing anything? Please advice.
Regards,
Jagannath
you may need to try and elevate their permissions in the code.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(web.Site.ID))
{
// implementation details omitted
}
});
run with elevated permissions
I have created a CustomAction feature to add a button to the "Actions" menu on a list. When I don't specify the ControlAssembly/ControlClass attributes then the button shows up. When I specify those attributes the button does not show up. I have tried adding a matching SafeControl element in the site web.config. I am using VSeWSS.
UPDATE - removed link to other question - not sure how i did that.
My question is can anyone tell me why my CustomAction button is not showing up when I specify the ControlAssembly and ControlClass attributes ?
UPDATE 2 - RegenConfigTemp actually does inherit from WebControl, sorry! My machine with web access is different from my dev machine and there is no way to move files between them short of burning a CD.
here are my files:
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<Solution SolutionId="GUIDHERE" xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureManifests>
<FeatureManifest Location="RegenConfigTemp\feature.xml" />
</FeatureManifests>
<Assemblies>
<Assembly Location="WebFeature.dll" DeploymentTarget="GlobalAssemblyCache" />
</Assemblies>
</Solution>
feature.xml
<Feature Id="GUIDHERE" Title="RegenConfigTemp" Scope="Web" Version="1.0.0.0" Hidden="FALSE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="RegenConfigTemp\Module.xml" />
</ElementManifests>
</Feature>
Module.xml
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="GUIDHERE" xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="GUIDHERE"
RegistrationType="List"
RegistrationId="1981"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
Title="Regenerate List Contents"
ControlAssembly="WebFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=myPKTokenHere"
ControlClass="WebFeature.RegenConfigTemp"
></CustomAction>
</Elements>
RegenConfigTemp.cs
using System;
using System.Runtime.InteropServices;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebControls;
namespace WebFeature
{
[Guid("GUID HERE MATCHES 1st GUID in Module.xml")]
public class RegenConfigTemp : WebControl
{
protected override void OnLoad(EventArgs e)
{
this.EnsureChildControls();
base.OnLoad(e);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
}
}
}
I added the following to the web.config
<SafeControl Assembly="WebFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=myPKTokenHere" Namespace="WebFeature" TypeName="RegenConfigTemp" Safe="True" />
Turns out the problem was in Module.xml. I was missing the 'equals' sign after 'Version' in this (corrected) line:
ControlAssembly="WebFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=myPKTokenHere"
I got on the right trail b/c I discovered Sharepoint's diagnostic logging, and the first comment on this blog: http://blog.lostparticles.net/?p=23 was my problem exactly.
Thanks for y'alls help.
UPDATE: I had to fix web.config line as well. I ended up putting the safecontrol line in the manifest instead of directly in the web.config; thanks JMD. (BTW, why doesn't VSeWSS do that for me, when it does for web parts?)
Are you sure that your code is supposed to render anything? Which class are you inheriting from and where is your render code? Have you checked the SharePoint log for any exception?
This is not an answer to your question, but you can place your SafeControl tag in the manifest instead of the web.config.
Surely RegenConfigTemp should be inheriting from something? At present you're not adding any controls, so if you're overriding an empty control that would be why you're not seeing anything. If nothing else, try setting a breakpoint or adding some diagnostic tracing to CreateChildControls() to see if the code is executing.