Solved

FeatureActivated and how to crash gracefully

Posted on 2013-01-22
2
685 Views
Last Modified: 2013-01-25
Hello. I have nice FeatureActivated -method, but any error will crash whole page. How can I ask SharePoint to show nice exception message?

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try 
           {
              //Error. Field does not exist etc.
            }
            catch(Exception e)
            {
                throw new SPException("xxx." + e.Message);
            }
        }

Open in new window

0
Comment
Question by:tolppa
2 Comments
 
LVL 14

Accepted Solution

by:
KoenVosters earned 500 total points
ID: 38805262
http://koenvosters.wordpress.com/2009/07/31/howto-create-an-event-handler-for-sharepointmoss-2007/

public override void ItemAdding(SPItemEventProperties properties)




{




 if (properties.AfterProperties["CheckValue"].ToString() == “dontadd”)




{




 properties.ErrorMessage = string.Format(“The CheckValue column equals dontadd -> item will not be added.”);




 properties.Status = SPEventReceiverStatus.CancelWithError;




 properties.Cancel = true;



 

}



}
0
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 38805374
KoenVosters: There's no error message property on the SPFeatureReceiverProperties instance?
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sharepoint 2010 2 27
Why use this lambda? 12 60
I need help adding validation to my MVC.Net view 6 21
sharepoint 2016 Document libraries and file sharing 6 16
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question