Posted on:
Categories: SharePoint
Description:

​My Add New Item link went missing the other day and I spent hours looking for it.

You see, I created a Custom List template using Visual Studio 2012’s new List item element. It added a list template and a list instance to my SharePoint 2013 project. I deployed the project to my publishing site and added this list into a HTML field within a publishing page. Here whether I set the List View Toolbar Type to "Full Toolbar" or "Summary Toolbar", the Add New Item link refused to show.

If I create a custom list via the browser UI and add it to a publishing HTML field, I can see the Add New Item link when I set the Toolbar Type to "Summary Toolbar". This pointed me to take a look at the list schema generated by Visual Studio 2012 and I noticed something was missing.

List schema generated by Visual Studio 2012 based on a Custom List:

...
<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
     ...
     <Toolbar Type="Standard" />

Out-of-the-box list schema for a Custom List:

<View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
     ...
     <Toolbar Position="After" Type="Freeform">
          <IfHasRights>
               <RightsChoices>
                    <RightsGroup PermAddListItems="required" />
               </RightsChoices>
               <Then>
                    <HTML><![CDATA[<div class="tb"><img
                    src="/_layouts/15/images/caladd.gif?rev=23" alt="" />&#160;<a
                    class="ms-addnew" id="idAddNewItem" href="]]></HTML>
                    <URL Cmd="New" />
                    <HTML><![CDATA[" onclick="javascript:NewItem(']]></HTML>
                    <ScriptQuote NotAddingQuote="TRUE">
                         <URL Cmd="New" />
                    </ScriptQuote>
                    <HTML><![CDATA[', true);javascript:return false;" target="_self">]]></HTML>
                    <HTML>$Resources:core,addnewitem;</HTML>
                    <HTML><![CDATA[</a></div>]]></HTML>
               </Then>
          </IfHasRights>
     </Toolbar>

I replaced <Toolbar Type="Standard" /> with the toolbar definition above and got my Add New Item link back. Schemas generated for custom document libraries have similar issue. Fixing it is easier though. You only need to remove <Toolbar Type="Standard" /> as the generated schema already contains the toolbar definition a few lines below it.

By the way, this issue seems to happen in publishing pages only. If you are using these custom libraries and lists in web part pages, the Add New Item/Document link shows normally.