Thursday, June 27, 2013

Event logging mechanisms in SharePoint and other .net applications

While developing business applications, it’s important to implement a logging infrastructure to help other developers, administrators and System support engineers to trace the issue. Many different approaches are in practise today, although in this blog I am going to write different scenarios and different approaches we have adopted within different projects so far.
Scenario 1:
Application type - ASP.NET application
In one of asp.net web application for hospital management, on an event of processing a pdf document, results and logs were inserted into database. This required implementing a custom logging mechanism.
Scenario2:
Application type - Windows forms
Custom migration tool for migrating from documentum to SharePoint, we used custom text file based logging mechanism using log4net.dll. This is very nice custom tool available handling multithreading and highly configurable to define file names, new file creation rule and much more. Visit http://www.codeproject.com/Articles/140911/log4net-Tutorial for more info.
Scenario3:
Application type - SharePoint 2007 custom build intranet application
While developing a custom content management system where support team and infrastructure administration teams were two different silos, a hybrid logging approach was implemented. Logs which can be useful at L3 and L2 support tickets, were written to custom SharePoint list. Also other logs were written to ULS logs.
Note: Building logs based on SharePoint list, requires a good trashing mechanism to delete logs older than 2 months.
Scenario4:
Application type- SharePoint 2010 publishing site based intranet application
There are couple of options implementing logging within SharePoint applications. Selecting one of these options depends on many factors like timelines, clients preference, existing organizations approved practices, etc.
  1. SharePoint Guidance library: provides easy to reuse methods utility that can be easily employed in time crunched projects.
    http://msdn.microsoft.com/en-us/library/ff798385.aspx
  2. Building custom LoggingService implemented by inheriting SPDiagnosticsServiceBase. This provides better classification of ULS logs over logs created using method SPDiagnosticsService.Local.WriteTrace
    http://blog.mastykarz.nl/logging-uls-sharepoint-2010
I haven’t got any opportunity to explore any new and better mechanism available with SharePoint 2013 so far.

Tuesday, June 25, 2013

Online learn application for html5, CSS3, jQuery

Recently came across a very good online academy to learn jquery, javacript, Html5 and CSS3. It’s very intuitive and gives quick starting for newbie's.
http://www.codecademy.com/learn
Thought of sharing it.

Monday, June 24, 2013

Release management: Need for custom script to Auto publish documents


In one the release, a custom sequential approval workflow on document library was upgraded to make use of Publishing approval mechanism
    This enabled the process to make use of draft item security section to provision
  • Check out- check in mechanism with a security filter (check out documents were shown to document author and approver alone)
  • Previous approved versions of checked out document were searchable to all users
Enabling this to existing setup with live users has many challenges. And a proper release planning is required for such implementations.
This upgraded workflow and document library setting updates developed and tested well in Dev environment. This setup was to be updated to more than 6 production sites. Some discrepancies were found on these sites.
    After analysing different project sites, following facts were identified:
  • Few document libraries has checked out approved document.
  • One document library had minor versions of the document – which are in approved state. (this was due to document library level settings wasn’t done appropriately)
These challenges were mitigated by executing custom scripts to undo checkout and auto publish documents to major version before associating the new upgraded workflow to the document library.

SPFile object provides below methods that were useful doing this: 1. Publish ( string comment);
2. Approve ( string comment);
3. UndoCheckOut ();

We need to be cautious that this script is ran when custom workflow is configured to not allow any new workflow instances on the specific document library. And again along with custom script building to support this task, as a part of stakeholder management, the document authors and site owners were engaged to explain the reason and communicate the actions taken on their documents as a System approved major versions.

Saturday, June 8, 2013

Automating relaunching workflows

This is in continuation of previous blog where I promised to highlight more on process of relaunching workflows. When a new version of workflow is republished, the approval task item links get broken for the workflows already started. Instances of the workflows that are started after the workflow is re-published will use the updated custom task edit forms. Restarting workflow consists of steps to
  1. Terminate existing workflow – This will also ensure deleting any tasks created for the workflow
  2. Start new workflow
Other things to be considered before stating this process
  1. Disabling outgoing email alert notifications on Tasks list (if any)
  2. Our custom workflow utilises a configuration list where sending custom emails on task creation was one of the turn on and turn off kind of parameter.
After analysing the number of workflows to be relaunched and availability of change window to execute any custom script on the server, decision about automating this relaunching process can be taken.
For SharePoint 2010 implementation - Here is a good source for power shell commandlets script for restating workflows.
Useful commandlet:
  • [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);
  • $SPList.Parentweb.site.workflowmanager.startworkflow($item, $WFAssociation, $WFAssociation.AssociationData)
Here below is a good example available : http://oszakiewski.net/eric/stop-and-restart-specific-item-workflows-in-sharepoint-2010-powershell For SharePoint 2007 implementation - a custom console application can be created using SP object model using below methods
  • SPWorkflowManager.RemoveWorkflowFromListItem(SPWorkflow workflow)
  • SPWorkflowManager.StartWorkflow(SPListItem item, SPWorkflowAssociation association,string eventData)

Friday, May 31, 2013

Managing SharePoint Workflow releases

Couple of months ago, I was in working on project where SharePoint based workflows were enhanced in phases and republished in multiple releases. Such projects with multiple releases in tight timelines, release planning plays an important role. And hence thought of making a checklist of things to be considered while doing such multiple releases.
  1. Identification and bookings for change windows for deployment process
  2. Identification of number of workflows in progress
  3. Identification of process to relaunch the workflows which are in progress status
  4. Engaging Change management team to getting communications for
    • Change in the workflow process
    • System outages if any
    • Relaunch of the workflows, broken approval links

In coming blogs will try to list down the challenges faced and workarounds used for them.

Monday, May 27, 2013

Comparing PL-SQL with TSQL

Recently I came across a project where I need to connect to oracle database for fetching my result set. Having always involved in microsoft technology stack projects, and very familier with the T-SQL, I find working with PL-SQL wasnt that different. Although I had to google for some function names corresponding to sql functions I was comfortable with.

functions comparison between PL-SQL and T-SQL

FunctionT-SQL PL-SQL
Current date GetDate()
GetUTCDate()
Sysdate
Current_date
Current timestamp SysDateTime Current_TimeStamp
systimestamp
Get maximum value of the column Max() max()
Get year from date field Year(DOB) to_char(DOB, ‘yyyy’)
Get Month from the date field Datename(mm,DOB)
Other formats m, month
to_char(DOB, ‘MON’)
Other formats can be MM, MONTH, mon
Get Day of week Datename(dw, DOB)to_char(DOB, ‘DAY’)
Specific Date format SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY] To_char(DOB, ‘dd/mm/yyyy’)
Finding index of (Location of text)CHARINDEX ( expressionToFind ,expressionToSearch [ , start_location ] )
e.g. CHARINDEX('@','someone@somewhere')
Instr(expressionToSearch, expressionToFind [, start_position [, nth_appearance ] ] )
e.g Instr('someone@somewhere', '@')

Finding tables with given column name

Not in all projects, enough Knowledge transfer is provisioned to understand complete database architecture. In such scenarios, we end up exploring the database tables and columns to understand their relationships or to just find out if such column exists and in which table. In SQL server, we have tables called sys.Tables and sys.Columns and by writing a simple query like below, it can be done.

USE AdventureWorks
GO
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%EmployeeID%'
ORDER BY schema_name, table_name;


After googling and altering the query, I came up with the PL-SQL query as below:

select a.table_name, column_name,DATA_TYPE,DATA_LENGTH from all_tab_columns a,USER_ALL_TABLES u
where a.TABLE_NAME=u.TABLE_NAME
and column_name like 'FAMILY_TYPE%'

[Note: default T-SQL like clause works as case-insensative, while with PL-SQL like clause works as case-sensative]

First Sunday of October month (Daylight saving ending date)

In SQL server, this requires a bit of query while in PL-SQL a simple function is available

Declare @D Datetime
Set @D = DateTime(‘01/10/2013’)
Select DateAdd(day, (8-DatePart(weekday,
DateAdd(Month, 1+DateDiff(Month, 0, @D), 0)))%7,
DateAdd(Month, 1+DateDiff(Month, 0, @D), 0))


With in PL-SQL

Select next_day(to_date('01/10/2013','dd/mm/yyyy'), 'Friday') from dual  

Monday, November 5, 2012

Xslt rendering tag < I> using SharePoint webpart

A weird issue of rendering tags I incorrectly was observed while working with xslt with SharePoint 2010 ootb rss viewer webpart. The xslt sample is
  • Although the xslt rendered complete content into italic format. After arealising and searching on net we figured out that thsee tags when rendered as variable gave expected behavior. The charged xslt looks like Hope this helps for someone facing similar issues.

    Thursday, February 9, 2012

    How to avoid checkout and check-in clicks with simple custom button

    For one of the clients, we wanted to simplify the process of updating document properties on the document library with Requires Checkout enabled.
    The process of checkout, then edit and again check in was little annoying for the end users. The solution developed was having Data view web-part with link button to edit form with check in button.

    The first milestone: Get Checkout alert and open edit link
    It was done using the js method STSNavigateWithCheckoutAlert. The syntax can be observed using IE developer tool. Please refer this link (Open document in Edit mode) for more insights on different js methods on document name context menu.
    The second milestone was to check-in item on saving item in edit form. This was achieved by getting check in button as we get on document upload page with a small trick of having query string as &Mode=Upload. Please refer this link for checkin button on edit form
    And the finally the javascript looks like
    onclick="STSNavigateWithCheckoutAlert('http://mysite/mylist/Forms/EditForm.aspx?ID=' + {@ID} + '&Mode=Upload', 1,0, 'http://mysite/mylist/' + '{@FileLeafRef}', 'http://mysite’)"

    Saturday, January 14, 2012

    SharePoint designer workflow activity: Set content approval status

    SharePoint 2007 provides document library with a content approval mechanism, useful for document versioning, approval before publishing content publically. Although lacks in assigning task and sending notifications to approvers. Also defining alerts on the custom views using Approval Status column is not possible here.
    The simple alternative was to build a SharePoint Designer workflow. One of the activity needed was to change one of the custom properties and set the Approval status to “Pending” after collection data on completion of task from approver.
    And the action activities flow used was
    1. Check out current item
    2. Set custom properties fields with variables
    3. Check in current item with comments
    4. Set content approval status to Pending

    Although all steps are logically correct, workflow yielded in Error.
    After googling for some time, came to forum link providing solution. After adding a delay of 1 minute it started working fine.
    New activities flow is
    1. Check out current item
    2. Set custom properties fields with variables
    3. Check in current item with comments
    4. Pause for duration 1 minute
    5. Set content approval status to Pending

    Workaround: Refinement panel stops working when setting Fixed Keyword Query

    Recently when working with SharePoint 2010 Search results customization, I experienced weird behavior “Refinement panel stops working when setting Fixed Keyword Query”.
    We had customized refinement panel to display custom metadata columns into search results by adding Custom Filters and wanted to display only documents as results. To filter only documents into search result, Fixed keyword Query isDocument:1 and Cross-Web part ID changed to Query2. And refinement panel stopped working.
    After playing around with different options, I figured out that, placing static filter IsDocument:1 into Append Text to Query instead of Fixed keyword query option solved the problem.

    Checkpoint for using Fixed Keyword Query:
    [If you configure a fixed keyword query, you must change the default Cross-Web Part Query ID setting in the Results Query Options node of this Web Part from the default setting of User Query to another query ID on the list, such as Query 2. If you do not change this value, the filter in the Fixed Keyword Query setting is not added to the search query.]
    Reference: http://technet.microsoft.com/en-us/library/gg549987.aspx

    Wednesday, January 4, 2012

    SharePoint 2007 and SharePoint 2010 configuration limitations

    It had been a very long time writing any blog. I was very busy with the critical project delivery. Now as have some free time, thought will start blogging again in this New Year. Wishing you all a very Happy New Year!!!

    Recently I was working on new project based on SharePoint 2007 and we had used most of the OOTB features to implement a collaboration portal for client. While implementing the solution, I rediscovered (being involved in custom solutions most of the time, we tend to never face these issue) few SharePoint 2007 limitations for OOTB configurations on lists and libraries. And later tried same configurations on SharePoint 2010 and concluded that these limitations do persist with newer version of SharePoint (2010).
    Things that are not changed in SharePoint 2010 and have same limitations as SharePoint 2007 are:
    1. Cannot define Default value for Lookup columns
    2. Cannot define list/library view with Grouped by column of Allow Multiple Selection enabled.
    3. Cannot set alerts on the custom view for filtering records based on document approval status column.
    4. Calculated column has restriction of nested if count as 6/ 1024 characters whichever encounters first.

    Tuesday, February 23, 2010

    How to apply Custom master page on specific page of the site?

    Recently we face a situation where on the publishing site, we had two master pages. One for home page with some jazzy look and other pages with simpler branding.

    Simple solution could be creating new Page Layouts, referring another master page.

    Here are the simpler steps to achieve this.

    1. Create a new Page Layout (either by using SharePoint designer or manually creating new aspx page)
    2. Specify custom.master as the MasterPageFile attribute for the page directive.

    MasterPageFile="~masterurl/custom.master"

    1. On PreInit event, change the MasterPageFile url to required master page.
    <script runat="server">

    void Page_PreInit(Object sender, EventArgs e)

    {

    this.MasterPageFile = "~SiteCollection/_catalogs/masterpage/myCustom.master";

    }

    </script>

    1. This may lead to error with “Code-blocks are not allowed in this file.”

    PageParserPaths is a special node in web application's web.config file. By Default this node is empty. You can add nodes to specify the virtual paths where you want to allow server side scripts:

    <pageparserpaths>

    <pageparserpath virtualpath="sites/mysite/_catalog/masterpage/*" compilationmode="Always" allowserversidescript="true" includesubfolders="true">

    </pageparserpaths>

    Wednesday, December 2, 2009

    How to set custom document template to document Library programmatically?

    Setting custom document template to SharePoint document library involves two steps:
    1. Upload template document to the Forms Directory of SharePoint document Library
    FileStream stream = File.OpenRead(@"c:\doc.doc");

    byte[] content = new byte[stream.Length];
    // Read the file from the stream into the byte array
    stream.Read(content, 0, (int)stream.Length);
    stream.Close();

    // Give the file a name, used as the name of the list
    // item once it gets into the document library
    string fileNameOnceInLibrary = "NewTemplate.doc";

    SPList list = CurrentWeb.Lists[“Shared Documents”];
    //CurrentWeb is assumed to be created..

    SPDocumentLibrary docLib = list as SPDocumentLibrary;
    SPFolder DocParent = web.Folders[strDocLibName];
    SPFolder formsFolder = DocParent.SubFolders["Forms"];

    // Add the file to the Files collection and commit to database
    SPFile file = formsFolder.Files.Add(formsFolder.Url + "/" + fileNameOnceInLibrary, content, true);

    formsFolder.Update();

    1. Setting the DocumentTemplateUrl property for the document library:

    docLib.DocumentTemplateUrl = file.Url;

    docLib.Update();

    Wednesday, September 30, 2009

    Issue with Content Type Required field

    Recently while creating a custom content type feature, I realized the fields are coming as Optional even after setting attribute Required = “true”

    <FieldRef ID="{3154C55D-956E-4049-831F-39AFF3AB7787}" Name="Patient" Required="true" ShowInDisplayForm="true" ShowInNewForm="false" ShowInEditForm="true" />

    After changing the attribute value to TRUE (uppercase), Content type fields worked fine.

    <FieldRef ID="{3154C55D-956E-4049-831F-39AFF3AB7787}" Name="Patient" Required="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="FALSE" ShowInEditForm="TRUE" />

    Reading lookup field value from SharePoint List item

    While reading a lookup column value, it is observed that value returns contains a number and character # followed by the actual lookup value selected. Spitting or substring the value may not be the right way to extract the actual lookup value.

    SharePoint provides a object SPFieldLookupValue to read Id and the Value of referenced list item.

    using (SPSite site = new SPSite(“http://localhost”))

    {

    using(SPWeb web = site.OpenWeb())

    {

    SPList list = web.Lists[“MyList”];

    SPListItem item = list.Items[0];

    String strvalue = item[“lookupColumn”];

    //this value comprises of number (id) and the lookup value with #.

    SPFieldLookupValue lookup = new SPFieldLookupValue(strvalue);

    String myLookupValue = lookup.LookupValue;

    //lookup.LookupId returns the id for the referenced list item

    //reading multi-valued lookup field value
    SPFieldLookupValueCollection lookupCollection = new SPFieldLookupValueCollection(strvalue);

    List<string> strLookupValues =new List<string>();

    foreach( SPFieldLookup lookupItem in lookupCollection)

    {

    strLookupValues.Add(lookupItem.LookupValue);

    Console.Write(lookupItem.LookupValue);

    }

    }

    }

    Friday, October 3, 2008

    Easy way to Redirect Users to an Error Page and Success page in SharePoint

    While developing custom application Pages and web parts we mostly come across
    the scenario for redirecting user to Some Error Page or Redirecting user to some
    default page after successful operation.
    WSS 3.0 provides a very easy and consistent way to provide this.
    Just a single line of code; Below here is the sample code
     1. TransferToSuccessPage :
      SPUtility.TransferToSuccessPage("Operation was completed",
    @"/Docs/default.aspx", "", "");




    2 . TransferToErrorPage :

    try
    {
    //Code that might cause an exception
    }
    catch (Exception ex)
    {
    SPUtility.TransferToErrorPage(ex.Message);
    }

    Monday, July 21, 2008

    Multiple Lists Data into a Single data view - using SharePoint Desinger


    Recently I came across a situation where we need to display a report with multiple SharePoint lists having one column “CategoryID” of type Number in common with minimum efforts or no code.

    The environment expected for this solution was a Windows SharePoint Services 3.0; Which limits us from using Content Query Web part (which is MOSS only feature) with cross List Queries.

    We came across a beautiful feature of Microsoft SharePoint Designer which facilitates to display data from multiple resources into a single Data View. http://office.microsoft.com/en-us/sharepointdesigner/HA100991441033.aspx

    The sample explained here contains creating XML files for the Data Sources. Any Existing SharePoint Lists can be considered as a Data Sources.

    Using this way we can easily create a dynamic view from multiple lists. Although the major disappointment here is : No Filter, No Sorting is supported. This will also not have Export to Excel feature as well

    With Some play around using Microsoft SharePoint Designer on the Data View Web part we can achieve Grouping.




    Sunday, June 22, 2008

    How to remove the 'title column' from a SharePoint list?

    Here by I am posting a very simple workaround to get rid of default column “Title” from any SharePoint List. When we create a SharePoint List, a default column “Title” gets created. While customizing Lists , we often come across a situation where we do not want this “Title” column.

    The fist way to deal with this scenario can be :

    1. We can make it a non-required column and take it out of the default view and that way we will not have to deal with it anymore. However, we cannot delete it.
    2. Or When we customize our list, rename the Column name for “Title” with any of the needed column, which is required to be Single Line text.

    Friday, June 20, 2008

    Custom Site definition with WSP does not show custom lists on Quick Launch navigation bar.

    Recently I came across a requirement where I had to create a custom site definition with custom lists , custom content types and document libraries. I found providing site definition as a WSP file is the best way and using SharePoint Solution Generator I created WSP file for my customized site. [ To learn how to use SharePoint Generator to create WSP files, refer link : http://weblogs.asp.net/soever/archive/2006/11/11/SharePoint-Solution-Generator-_2D00_-part-1_3A00_-create-a-site-definition-from-an-existing-site.aspx ]

    My original site had few of my custom lists links available on Quick Launch Bar. And visual studio project created for the site also had SharePoint Solution settings Quick Launch Default Option as TRUE

    When I created a Site based on this new site template (Development site template section), site did not had these custom lists availble on Quick Launch Navigation bar. Although custom List instances were available on the site.

    As my search, it seems that Quick launch navigation customizations gets lost using SharePoint Solution Generator.
    [Here is the good link illustrating limitations of SharePoint Solution Generator : http://www.mtelligent.com/journal/2007/10/13/overcoming-the-limitations-of-the-sharepoint-solution-genera.html ]

    Fix: -

    In Onet.XML file for the site definition file,

    1. Find Configuration section
    2. Find List element for your custom list definition
    3. Add attribute QuickLaunchUrl="Lists/MyCustomList/AllItems.aspx"
    4. Rebuild the application
    5. Deply the application to get new updated WSP file.

    Friday, February 8, 2008

    How to hide Upload Toolbar button from a Forms Library?

    Last month, I came across a requirement where I need to hide Upload toolbar button on one of our forms library. I tried to find on net, and got some clues how to do this. Adding a custom control under c:\Program Files\Common Files\Microsoft shared\Web service extensions\12\Template\CONTROLTEMPLATES, this can be done.

    Reference: http://blogs.msdn.com/dipper/archive/2006/10/05/How-to-Remove-or-hiding-items-in-List-toolbar-in-Sharepoint-Server-2007.aspx

    But using this way, It hides toolbar buttons for all of the document library and Forms library. Following is the workaround to hide toolbar buttons on specific forms library.

    Step 1: Design a InfoPath Form with some controls on it.

    Step 2: Publish InfoPath form as a Site Content Type “MyCustomContentType” on Forms Template Library

    Step 3: Using Visual Studio Sharepoint tools, Create custom list definition for Forms Library. Tool used is Visual Studio 2005 extensions for Windows SharePoint Services 3.0, Version 1.0) Tools for developing custom SharePoint applications.

    Step 4: Under Schema.Xml add attribute ToolbarTemplate=”myToolBarID” to <View BaseViewID="1" > element as follows

    <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,All_Tasks;" DefaultView="TRUE" MobileView="True" MobileDefaultView="False" ToolbarTemplate="myToolBarID” SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/issues.png" Url="AllItems.aspx>

    Step 5: Build the custom form library definition and deploy it/

    Step 6: Create a forms library based on this newly created definition.

    Step 7: Toolbar for the newly created forms library will be missing.

    Step 8: Save following code snippet as MyCustomFormLibToolBar.ascx into c:\Program Files\Common Files\Microsoft Shared\Web Service Extensions\12\Templates\CONTROLTEMPLATES

    <%@ Control Language="C#" AutoEventWireup="false" %>

    <%@Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    <%@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>

    <%@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>

    <%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" %>

    <%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" %>

    <SharePoint:RenderingTemplate ID="myToolBarID" runat="server">

    <Template>

    <wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="''" RightButtonSeparator=" " runat="server">

    <Template_Buttons>

    <SharePoint:NewMenu AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>

    <SharePoint:ActionsMenu AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>

    <SharePoint:SettingsMenu AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server"/>

    </Template_Buttons>

    <Template_RightButtons>

    <SharePoint :PagingButton runat="server"/>

    <SharePoint:ListViewSelector runat="server"/>

    </Template_RightButtons>

    </wssuc:ToolBar>

    </Template>

    </SharePoint:RenderingTemplate>


    Step 9: IISReset

    Step 10: Toolbar for the newly created Forms library is available.

    Step 11: Open Advance Settings for the Forms Library settings

    Step 12: Check Allow multiple content types, Open as Web Page.

    Step 13: Select Add existing content type, and add “MyCustomContentType”.

    The similar ascx control can be used to hide or remove toolbar buttons on specific SharePoint List, Document Library as well.