Question

How can I validate a custom web part property in a Sandbox solution (SharePoint Online 2013 environment)?

I am throwing a WebPartPageUserException when validation fails, as shown below.

private string fileName = "test";

[WebBrowsable(true),
Category("Custom Properties"),
Personalizable(PersonalizationScope.Shared),
WebDisplayName("Template File Name")]
public string TemplateFileName
{
    get { return fileName; }
    set
    {
        if (string.IsNullOrEmpty(value))
            throw new WebPartPageUserException("Template File Name cannot be empty.");

        fileName = value;
    }
}

Throwing the WebPartPageUserException exception is breaking the web part; it starts displaying this error message:

Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. Correlation ID: 1e535d9c-0f00-e011-b94d-8fb08e826bea.

ULS logs the below error:

SPNavigationNode previousSibling, PortalSiteMapNode parentNode)    
 at Microsoft.SharePoint.Publishing.Navigation.PortalWebSiteMapNode.PopulateNavigationChildrenInner(NodeTypes includedTypes)    
 at Microsoft.SharePoint.Publishing.Navigation.PortalWebSiteMapNode.PopulateNavigationChildren(NodeTypes includedTypes)    
 at Microsoft.SharePoint.Publishing.CachedArea.CreateRefreshedVersion(List`1& newObjects)    
 at Microsoft.SharePoint.Publishing.CachedObjectFactory.ReSyncChangedCache()".

I thought the error might be related to the left navigation menu, so I tried removing it from the page (just in case). But this did not have any effect.

I have also tried deploying to several different environments and site collections, with no luck.

Can a WebPartPageUserException be thrown from a Sandbox solution? If not, what is the suggested way for handling custom web part property validation?

Thank you for your help.

Was it helpful?

Solution

As you guessed, this is not allowed from inside a sandboxed solution.

You're going to have to test the value some way or the other, and maybe render a message to the user inside the webpart itself.

Related question here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top