0

I'm little confused with the creation of a custom WebControl for a CustomAction.

I was following this tutorial : https://weblogs.asp.net/jan/creating-hierarchical-menus-with-a-customaction-in-sharepoint, but in my case nothing happens.

I guess it is because I don't how to create the class which inherits from WebControl. How do I have to create this class? I have to click on "Add a item", then "User Control (Farm Solution only"? Or I have to click just on "Class" classic? But for the last solution, how can I add this class to my assembly?

Here the code :

Elements.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="Essai"
    Location="Microsoft.SharePoint.StandardMenu"
    GroupId="SiteActions"
    ControlAssembly="XXX"
    ControlClass="XXX.Web.CustomisationSiteActions">
  </CustomAction>
</Elements>

In CustomisationSiteActions.cs :

using Microsoft.SharePoint.WebControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;

namespace XXX.Web
{
    public class CustomisationSiteActions : WebControl
    {

        // Add a the new "lol" menu item
        protected override void CreateChildControls()
        {
            MenuItemTemplate item = new MenuItemTemplate();
            item.Text = "lol";
            item.Description = "lol";
            item.Sequence = 2005;

            this.Controls.Add(item);
        }  
    }
}

Thanks for your help.

  • Add new item, select class give it a name inherit it from System.Web.UI.WebControls.WebControl – akbar ali Dec 27 '16 at 12:22
  • Thanks, but I did it and nothing happens. I edited my post in ordre to show my very short code. – TWEESTY Dec 27 '16 at 12:30
  • Just for your information, we don't enter in the method CreateChildControls. – TWEESTY Dec 29 '16 at 7:29
1

Instead of changing the deployment target, add a safe control entry for your namespace of the control rendering the menu item.

  • Welcome to SharePoint StackExchange! Please expand your answer if possible with perhaps an example of a safe control entry. Thanks [mod]. – SPDoctor May 11 '17 at 7:40
0

I do not do back-end dev

From the client, run as a Snippet in ChromeDEV tools, it is:

var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
var actions = web.get_userCustomActions();
ctx.load(actions);
ctx.executeQueryAsync(function () {
        var userCA = actions.add();
        userCA.set_location('Microsoft.SharePoint.StandardMenu');
        userCA.set_group("SiteActions");
        userCA.set_sequence(922);
        userCA.set_description('MyDescription');
        userCA.set_title('MyTitle');
        userCA.set_url('MyUrl');
        userCA.update();
        ctx.executeQueryAsync(function () {
            console.log("Site action link added");
        }, function (e) {
            console.error(e)
        });
});
  • Thanks, it works but i'm always confused with my back-end dev. – TWEESTY Dec 27 '16 at 15:22
  • Front-End rules, back-end is the Cobol/Fortran of 2017 – Danny '365CSI' Engelman Dec 27 '16 at 15:58
0

I found the solution, it didnt't find the assembly. I had to change the value of "DeploymentTarget" to "WebApplication" in my Package.Template.xml.

Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.