Create context menu item in SharePoint List
1. Wrote Custom Action such as
<CustomAction Id="EditContentTypeColumns"
RegistrationType="ContentType"
RegistrationId="0x010100B652F1B8BDCE44e8AB6560178C412708"
Location="EditControlBlock"
ImageUrl="/_layouts/images/edititem.gif"
Sequence="303"
Title="$Resources:SPPublicDemoTemplates,editContentType">
<UrlAction Url="~site/_layouts/TemplateManagement/EditContentType.aspx?ListId={ListId}&ItemId={ItemId}&Source={SourceUrl}&SiteUrl={SiteUrl}"/>
</CustomAction>
2. Type ContentTypeId that's item has this custom action.
3. EditContentType.aspx - my page in sharepoint
4. Code of Edit ContentType
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace Voodoo.SPPublicDemo.Templates
{
public class EditContentType : LayoutsPageBase
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
using(SPSite site = new SPSite(Request.Params["SiteUrl"]))
{
SPWeb web = site.OpenWeb();
SPList list = web.Lists[new Guid(Request.Params["ListId"])];
SPListItem item = list.GetItemById(Convert.ToInt32(Request.Params["ItemId"]));
SPContentType type = site.RootWeb.ContentTypes[item.ContentType.Name];
Response.Redirect(String.Format("{0}/_layouts/ManageContentType.aspx?ctype={1}",
site.RootWeb.Url, type.Id.ToString()));
}
}
}
}
Комментариев нет:
Отправить комментарий