SharePoint 2013

SharePoint – Adding links on a page to create new documents using content types


Today I had a need to add a link to a page which would create a new document. The document library that I use has multiple content types and each contennewdoct type has a custom document template.

Rather than asking the users to click on the New document menu options I want a single button on the page that looks like this:

newnda

 

So first within a content editor on my page.

 

 

Then I created  a link in my html that looks like this:

<a onclick=”CoreInvoke(‘createNewDocumentWithRedirect2′,event,’https:\u002f\u002fportal.mycorp.com\u002fShared Documents\u002fForms\u002fNon-Disclosure%20Agreement\u002fNDATemplate.docx’, ‘https:\u002f\u002fportal.mycorp.com\u002fShared Documents\u002fNon-Disclosure Agreement’, ‘SharePoint.OpenDocuments’, false, ‘https://portal.mycorp.com/_layouts/CreateNewDocument.aspx?id=https://portal.mycorp.com/Shared%20Documents/Forms/Non-Disclosure%20Agreement/NDATemplate.docx&#8217;, true, 1); return false;” href=”#”>New NDA</a>

Ok, so on clicking the link  the folloing JavaScript is happening:

CoreInvoke(‘createNewDocumentWithRedirect2‘,event,’https:\u002f\u002fportal.mycorp.com\u002fShared Documents\u002fForms\u002fNon-Disclosure%20Agreement\u002fNDATemplate.docx‘, ‘https:\u002f\u002fportal.mycorp.com\u002fShared Documents\u002fNon-Disclosure Agreement‘, ‘SharePoint.OpenDocuments‘, false, ‘https://portal.mycorp.com/_layouts/CreateNewDocument.aspx?id=https://portal.mycorp.com/Shared%20Documents/Forms/Non-Disclosure%20Agreement/NDATemplate.docx‘, true, 1)

Ok, what does this all mean.

createNewDocumentWithRedirect2 – Is the function that is responsible for the opening Word.

event – this contains the event information of the as part of the onclick event.

https:\u002f\u002fportal.mycorp.com\u002fShared Documents\u002fForms\u002fNon-Disclosure%20Agreement\u002fNDATemplate.docx – This is my document template that I uploaded for my content type.

https:\u002f\u002fportal.mycorp.com\u002fShared Documents\u002fNon-Disclosure Agreement – This is the folder to my content type in the library.

SharePoint.OpenDocuments – SharePoint’s code to open documents

false – Not sure

https://portal.mycorp.com/_layouts/CreateNewDocument.aspx?id=https://portal.mycorp.com/Shared%20Documents/Forms/Non-Disclosure%20Agreement/NDATemplate.docx – This is the page that SharePoint calls to create new documents

true – Not sure

1 – Not sure

 

 

 

 

 

Advertisements

4 thoughts on “SharePoint – Adding links on a page to create new documents using content types

  1. Hi There,

    Thanks for sharing this. I’ve sadly had no joy at all getting this to work though.

    I’m trying to add a button to a page, that performs the (NEW ITEM) function for a doc library with an Infopath tempate (xsn).

    Perhaps because your example above was WORD this fails for me.

    Cannot find any explanation on web anywhere how to do this, so frustrating!

    Kind Regards,
    Paul

    Like

  2. Hi Peter,
    I got the Invoke command out of the html on the library new menu.I’m not 100% if this will be the same for InfoPath forms. The best way forward is to put your browser in debug ( F12 for most browsers) and then identify the html that has the onclick event specified.

    I currently don’t have an InfoPath form handy.I might be able to have a look into that later this week.
    Thanks,
    Pieter

    Like

  3. Thanks Pieter, I have been using Firebug to try and work out the JS needed. (I’m not a programmer! 🙂 )

    I managed to grab the HTML code for the default “NEW +” button for the doc library (with the Infopath template) and put it on another page on the site (which seems to work if I hide an app part of the library on the same page).

    This opens the Infopath (in Infopath) which is fine.

    Ideally though I would like to put a link to open this Infopath Template from another Site Collection completely. There is no way the button code below would work. I guess I need some real custom code.

    Button code..


    <button title="Create a new document or folder in this library." class="ms-qcb-button js-listview-qcbNewButton js-callout-body js-qcb-button js-callout-launchPoint " id="QCB1_Button1" role="button" accesskey="n" onclick="Renderer.FunctionDispatcher.Execute(this,0,"itemClick",event,Renderer.FunctionDispatcher.GetObject(0))" type="button" aira-expanded="false">New</span></button>

    Many Thanks
    Paul

    Like

Please leave a comment or feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s