SharePoint Display custom error Message in Errorpage

Normally the SharePoint errors are filled with messages that no user will understand followed by a correlation id. Well, the user knows there is an error, but what should he do next? It would be nice to give him some advice like try to refresh the page or anything. Therefore the SPUtility provides a nice solution. With TransferToErrorPage you can simply bring your own text into an error message. This is useful if you develop some features or custom pages or anything custom.

[sourcecode language=”csharp”]

SPUtility.TransferToErrorPage(string.Format(“Error loading List Form Page: {0}\r\n\r\nStack Trace:\r\n{1}”, ex.Message, ex.StackTrace));


SPUtility.TransferToErrorPage(“Dear User, there was an error. We apologize for that. Please refresh the page and try again.”);


The result of the error message is like this:


Looks better right?

But keep in mind: In this case there will be nothing added to ULS no logging entry is made. So you have to add it by yourself.


The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.

Be the first to comment

Leave a Reply

Your email address will not be published.