WSS 3.0 ItemAdded - sharepoint

I am working with WSS 3.0 and trying to set some permissions with the ItemAdded-Event.
The problem is, that the event dont fire if I add an item. I've searched the whole web and found nothing. It is only on ItemAdding / ItemAdded, yet I have already implemented a ItemUpdating and ItemDeleting Event which are working perfect! Are there known issues?
This is my Event (It not even get my debugmessages.. :( ):
public override void ItemAdded(SPItemEventProperties properties)
{
Debug.WriteLine("ItemAdded started.");
PMDB_ContentType_Class pmClass = new PMDB_ContentType_Class();
pmClass.SetPermissions(properties);
Debug.WriteLine("ItemAdded ended.");
}
This is the feature.xml
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="34e2c6bd-0e9f-4a65-b280-3cd4c5ff5cb4" Title="PMDB_ContentType"
Scope="Site" Version="1.0.0.0" Hidden="FALSE" DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="PMDB_ContentType\PMDB_ContentType.xml" />
</ElementManifests>
</Feature>

1 >> I hope that you have attached you event with your list properly in FeatureActivated Event receiver of Feature. I cannot check that because you haven't post that code. please check if there are any errors in that code.
2 >> Use Sharepoint Manager (http://spm.codeplex.com/releases/view/51438) to see if your event is properly attached to your list or not. if not then try to deactivate feature from web UI and reactivate it again.

Related

How to get userId for custom action in SharePoint

When implementing a List Menu Custom Action in Sharepoint 2013 I have problem getting which user has actually executed the custom action. I would like to do that to check that the user has permission to do this by checking which AD-groups the user is a member of. When I try to resolve the user with the Tokenhelper class it will only return the SharePoint system account sending the query to the Host Web. Is there any way you could attach the userId in the UrlAction parameters like below?
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="77cb35d9-1bf3-4d81-91cf-8a92473a6092.MenuItemCustomAction1"
RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="10001"
Title="$Resources:TogglePublic"
HostWebDialog="TRUE"
HostWebDialogHeight="250"
HostWebDialogWidth="700">
<UrlAction Url="~remoteAppUrl/CustomActionTarget.aspx?StandardTokens}&SPListItemId={ItemId}&SPListId={ListId}&SPSource={Source}&SPListURLDir={ListUrlDir}&SPItemURL={ItemUrl}&SPUserId={_spPageContextInfo.userId}" />
</CustomAction>
</Elements>
On the Host Web the following code should get the SPUserId:
public partial class CustomActionTarget : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
string userId = this.Request.QueryString["SPUserId"];
}
}
The _spPageContextInfo.userId is a javascript variable that should contain the current user, but I have not found any way to actually resolve and send the userId to the SharePoint App's Host Web using the UrlAction.

How to REpublish Custom Task Forms (InfoPath) to SharePoint 2010 State Machine Workflows

I am new to SharePoint. Sorry if answer to my question is obvious.
I've create Custom Task Form in InfoPath and publish it (File/Publish/Network Location [Form Template Path and filename='MYPROJECT/Forms/ApprovalForm.xsn'; Form template name='ApprovalForm'], in the next window I've cleared Public URL according to the article http://www.codeproject.com/Articles/195348/SharePoint-2010-State-Machine-Workflows-with-Custo).
After it I've added module Forms, and added ApprovalForm.xsn from the existing items.
My xml files:
Elements.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Workflow
Name="Order New Server"
Description="My SharePoint Workflow"
Id="482cbc86-b717-4981-a49a-3cf4c89e9399"
CodeBesideClass="Myproj.OrderNewServer.OrderNewServer"
CodeBesideAssembly="$assemblyname$"
TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160">
<Categories/>
<AssociationData><Data></Data></AssociationData>
<MetaData>
<AssociationCategories>List</AssociationCategories>
<Task2_FormURN>urn:schemas-microsoft-com:office:infopath:ApprovalForm:-myXSD-2012-03-09T14-11-55</Task2_FormURN>
<StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>
</MetaData>
</Workflow>
</Elements>
Feature.Template.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/" ReceiverAssembly="Microsoft.Office.Workflow.Feature, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Receiverlass="Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver">
<Properties>
<Property Key="GloballyAvailable" Value="true" />
<Property Key="RegisterForms" Value="Forms\*.xsn"/>
</Properties>
</Feature>
My form work fine, but when I make changes and republish it, it doesn't update (I see old form).
What I tryed:
IISReset
Clear all cookies and cache in IE
Retract solution, restart VS2010, reboot computer.
Change assembly number, guid.
I have no ideas, what can I try for republish my form with changes.
Thank you in advance for any suggestions.
PS: sorry for my writing. English is not my native language.
PPS: when I save new Form to new location and add it to the project, it works.
I've found how can I republish changes. But it seems more like crutch than solution, but it works: After republishing InfoPath form, I delete file from project (DEL on ApprovalForm.xsn in Solution explorer) and after it add it again. (Add/Existing Item). And then redeploy! Hurray!

I've got a sharepoint solution, what next

I'm new to sharepoint. I have a C# solution, that has masterpages and user-controls to be used in a sharepoint site. I have setup my sharepoint dev VM and i can browse the default sharepoint stuff.
How do I add the master pages to Sharepoint? Where do I go from here?
My suggestion would be to deploy the master pages as a feature rather than a manual process. Solutions (WSPs) and Features are the supported way to deploy content/features into sharepoint. A really great tool for sharepoint development is called WSPBuilder
A master page is deployed into sharepoint as a "module" that you will place into your elements.xml file in the feature.
Think of a solution as a .cab file with a different extension. Within that is a file called feature.xml which defines the title of your package when its deployed. Features can be activated and deactivated to deploy and undeploy your content into parts of your farm.
Here is an example of a css file deployed as a Module... Master pages would be similar however, they would deploy into the master page gallery rather than the style library. This module deploys a custom css file into the "Style Library" of a site collection. After this is deployed I used a "Feature Receiver" (event handler) to grab a reference to the SPSite object and modify its alternate stylesheet so that my override took place.
Feature.xml
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="63BB13A0-1F9C-4c3b-BE60-10E59CEE0113"
Title="Custom CSS Feature"
Description="Deploying a custom CSS using a feature"
Version="1.0.0.0"
Hidden="FALSE"
Scope="Site"
ReceiverAssembly="CustomCSSFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=24f1377a8414d2ed"
ReceiverClass="CustomCSSFeature.FeatureReceivers.CustomCSSFeatureReceiver"
>
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
elements.xml - you'd modify this to reflect where master pages are supposed to be deployed I would think that this is the Url property. The Path="Styles" refers to the relative path within the feature itself where the style sheet resides (e.g. in your visual studio i have a sub folder called styles beneath the folder called CustomCSSFeature and that is where the style sheet exists)
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="OSGStyles" Url="Style Library" Path="Styles" RootWebOnly="TRUE">
<File Url="custom-css.css" Type="GhostableInLibrary" />
</Module>
</Elements>
Then, in my feature receiver class I have activated/deactivated handlers which "apply" the stylesheet to the publishing web. In your case you can likely change the default master page for the website in a feature receiver as well.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.OpenWeb())
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.AlternateCssUrl.SetValue(web.ServerRelativeUrl +
"/Style Library/custom-css.css", true);
publishingWeb.Update();
web.Update();
}
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.OpenWeb())
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.AlternateCssUrl.SetValue("", true);
publishingWeb.Update();
web.Update();
}
}
Copy them to SharePoint root (For SP 2007 default location is C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\, for SP 2010 instead of "12" you have "SharePointRoot")
From there, copy your files to \TEMPLATE\LAYOUTS folder and then you can reference masterpage from your aspx pages like "/_layouts/mymasterpage.master".
UserControls goes into \TEMPLATE\CONTROLTEMPLATES
Get to know the directory structure in the 12 Hive
Exploring the 12 Hive : TEMPLATE Directory
Another way is to put your masterpage in master pages list. Use this link to access master page list and upload your masterpage: http:///_catalogs/masterpage
You can add master pages using the SharePoint Designer 2007.
Generally i recommend you to take a look at the answers of this question: Learning Sharepoint

Sharepoint 2010 Email Event Receiver not firing?

I have two event recievers setup on a list in 2010.
The first is a ItemAdded reciever that works every time:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="10000">
<Receiver>
<Name>ListItemReceiverItemAdding</Name>
<Type>ItemAdding</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SSW.TipDontRant.Sharepoint.ListItemReceiver</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
The second is an Email event reciever that I have only preiodicaly got to work.. In the 30-40 attempts to debug the applicaiton I have only had it work in 2 cases.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="10000">
<Receiver>
<Name>EmailReceiverEmailReceived</Name>
<Type>EmailReceived</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SSW.TipDontRant.Sharepoint.EmailReceiver</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
I have attached to the OWSTimer and the ListTemplateId is indeed correct.
On checking the log as sugested I found the follwoing error:
12/11/2009 17:12:54.01 OWSTIMER.EXE (0x2314) 0x046C SharePoint Foundation Monitoring nasq Medium Entering monitored scope (Timer Job job-email-delivery) 7b525bbb-0972-4115-97b1-19b1d94ff8c5
12/11/2009 17:12:54.03 OWSTIMER.EXE (0x2314) 0x046C SharePoint Foundation E-Mail 6873 Warning An error occurred while processing the incoming e-mail file C:\inetpub\mailroot\Drop\24c6872e01ca7a8500000003.eml. The error was: Object reference not set to an instance of an object.. 7b525bbb-0972-4115-97b1-19b1d94ff8c5
12/11/2009 17:12:54.03 OWSTIMER.EXE (0x2314) 0x046C SharePoint Foundation E-Mail 6871 Information The Incoming E-Mail service has completed a batch. The elapsed time was 00:00:00.0190038. The service processed 1 message(s) in total. Errors occurred processing 1 message(s): Message ID: <B05256D324B3D540853A95FF2AD9B257801F931C81#mooncalf> 7b525bbb-0972-4115-97b1-19b1d94ff8c5
12/11/2009 17:12:54.03 OWSTIMER.EXE (0x2314) 0x046C SharePoint Foundation Monitoring b4ly Medium Leaving Monitored Scope (Timer Job job-email-delivery). Execution Time=23.4762559268986 7b525bbb-0972-4115-97b1-19b1d94ff8c5
Its a little dificult to read here, but the important bit I think is:
An error occurred while processing the incoming e-mail file C:\inetpub\mailroot\Drop\24c6872e01ca7a8500000003.eml. The error was: Object reference not set to an instance of an object.. 7b525bbb-0972-4115-97b1-19b1d94ff8c5
Which does not tell me much! I do not think that it an error with my code, as it would throw within Visual Studio. I can confirm that emails sent to a document library work correctly as well.
Has anyone else had these problems?
Has anyone managed to get this to work consitantly?
[UPDATE] I left my code over the weekend, did not touch it at all, and now it is working! This seams to be very flacky on Sharepoints part.
So, I now have the line of my code that is failing (note that I did not get this far before) and it is on a reference to an external assembly for which I have opened another question Sharepoint 2010 Project package: Cannot add a new project output assembly to the package
It looks like this is a bug either in VS2010 Beta 2 or in Sharepoint 2010 beta.
To solve the imediate problem you need to delete the site, deactivate and remove the solution and then reboot your enviroment.
This only happens when you make structural changes to your lists and Event Recieves and only seams to affect the Email Event Reciever...

WSS 3.0 Site Definition breaks when including MasterUrl in onet.xml

I have created a simple site definition for WSS 3.0 which uses a feature, this feature provisions a master page into the masterpage gallery.
This works absolutely fine, and once I've created a site from the definition I can go into the masterpage gallery and view my provisioned file.
If, however, I set the MasterUrl in my Configuration node of onet.xml and then create a new site from it, it fails. After clicking create it redirects me to the new site automatically but presents me with a file not found error. So I type in the url to the settings page and click to view the masterpage gallery which then gives me a file not found error again.
I'm not sure what's going on, but it looks to me like setting the MasterUrl prevents it from creating the correct lists to which the feature can provision the masterpage to. Can anyone shed any light on this matter for me please?
Here is the webtemp*.xml:
<?xml version="1.0" encoding="utf-8"?>
<Templates>
<Template Name="MasterPageTest" ID="10902">
<Configuration ID="0"
Title="MasterPageTest"
Description="Testing master page deployment"
Hidden="FALSE"
ImageUrl="/_layouts/images/stsprev.png"
DisplayCategory="Test"
/>
</Template>
</Templates>
And the onet.xml (with the masterurl attribute removed):
<?xml version="1.0"?>
<Project Title="MasterPageTest" Revision="3" ListDir="$Resources:core,lists_Folder;" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- _locID#Title="camlidonet1" _locComment="{StringCategory=HTX}" -->
<NavBars>
</NavBars>
<ListTemplates>
</ListTemplates>
<DocumentTemplates>
</DocumentTemplates>
<Configurations>
<Configuration ID="0"
Description="Testing master page deployment"
Title="Master Page Test"
Name="MasterPageTest"
>
<!-- MasterUrl="_catalogs/masterpage/MasterPage.master" -->
<Lists>
</Lists>
<Modules>
</Modules>
<SiteFeatures>
</SiteFeatures>
<WebFeatures>
<!-- Masterpage -->
<Feature ID="8175B375-38F5-44E2-950A-9600D5427E17"/>
</WebFeatures>
</Configuration>
</Configurations>
<Modules>
</Modules>
<ServerEmailFooter>$Resources:ServerEmailFooter;</ServerEmailFooter>
</Project>
My first thought was: Why in the onet.xml?
I usually do this using a process called Feature stapling. It is impossible to remove / disable functionality created from a site definition later on (off course you could by hand, or a feature + receiver to remove say a list you don't need for a particular site created from the onet.xml, but you probably get the point).
By using feature stapling, (your / the) site definition stays clean and stays what it is meant to be: a definition of a site, that can be selected during site creation. IMHO, it should be nothing more than an empty container.
Feature Stapling binds features you want activated when a site is created to a (custom) siteTEMPLATE. You can even use this to attach features you want activated on out of the box site definitions as well. For instance, feature stapling is the preferred way of enabling features in the "MySite" and "My Site Host" definitions. The original sitedefintion remains untouched, but your features are activated too!
Now to actually answer your question: The masterpage is probably not available yet when the site definition is used, the onet.xml is processed before any features are activated.
If your site is a publishing site (meaning the publishing related features are activated in the site collection), you can set the masterpage in the Publishing Feature with the ChromeMasterUrl property.
If the site is a regular site, you can do 2 things:
deploy the master page from the onet.xml by moving the <Module> from your masterpage feature to the onet.xml, more info here (figure 1).
don't set the masterpage url in the onet, but use a feature + featurereceiver to set the masterpage url, more info here (downloadable code in article).

Resources