пятница, 2 октября 2009 г.

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}&amp;ItemId={ItemId}&amp;Source={SourceUrl}&amp;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()));
}
}
}
}

Remove new action in SharePoint Toolbar List.


Hi, everybody.

Not for a long time I wrote very simple demo for customers thats interesing in sharepoint port customization.

I encountered with problem: "How to remove new button in sharepoint toolbar in the certain list".

And I found decision.

1. Create in the 12/template/controltemplates file TemplateManagementToolbar.ascx












2. In schema.xml of your list definitions find




ToolbarTemplate is Id of our custom template toobar.

3. iisreset.

And it works!

Thanks.