Add custom action in edit contro block with code …

Actually very straight forward if you are a SharePoint Developer:

 

public class MUACSupplierPerformanceEventReceiver : SPFeatureReceiver
{

public const string ACTION_GENERATE_REPORT = “Generate report”;

// Uncomment the method below to handle the event raised after a feature has been activated.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPWeb spWeb = properties.Feature.Parent as SPWeb)

{

if (spWeb.ListExists(GeneralResources.ListNames.SUPPLIER_PERFORMANCE_EVALUATION))

{

spWeb.AllowUnsafeUpdates = true;

SPList spList = spWeb.Lists[GeneralResources.ListNames.SUPPLIER_PERFORMANCE_EVALUATION];

RemoveAction(properties);

SPUserCustomAction useraction = spList.UserCustomActions.Add();

useraction.Name = ACTION_GENERATE_REPORT;

useraction.Location = “EditControlBlock”;

useraction.ImageUrl = “/_layouts/Images/fcoscorecard.png”;

useraction.Url = “{SiteUrl}/_layouts/EuroControl/SupplierPerformanceQuestions.aspx?itemId={ItemId}”;

useraction.Sequence = 106;

useraction.Title = ACTION_GENERATE_REPORT;

useraction.Update();

spList.Update();

spWeb.AllowUnsafeUpdates = false;

}

}

});

}

catch (Exception ex)

{

SPTUlsLog.WriteError(ex, SPTUlsLog.Error);

}

}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

{

RemoveAction(properties);

}

private void RemoveAction(SPFeatureReceiverProperties properties)

{

try

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPWeb spWeb = properties.Feature.Parent as SPWeb)

{

if (spWeb.ListExists(GeneralResources.ListNames.SUPPLIER_PERFORMANCE_EVALUATION))

{

spWeb.AllowUnsafeUpdates = true;

SPList spList = spWeb.Lists[GeneralResources.ListNames.SUPPLIER_PERFORMANCE_EVALUATION];

foreach (SPUserCustomAction action in spList.UserCustomActions)

{

if (action.Title.Equals(ACTION_GENERATE_REPORT))

{

action.Delete();

spList.Update();

break;

}

}

spList.Update();

spWeb.AllowUnsafeUpdates = false;

}

}

});

}

catch (Exception ex)

{

SPTUlsLog.WriteError(ex, SPTUlsLog.Error);

}

}

}

}

 

 

The image url is ignored in SharePoint 2013, because it does not use icons.

 

Hope it helps

 

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit /  Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit /  Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

w

Verbinden met %s