Quantcast
Channel: Frederik Prijck » office 2003
Viewing all articles
Browse latest Browse all 2

Add “New Document” link you your custom application page

$
0
0

When working with SharePoint document libraries there are two ways to add new files: update file and add new.
The “Add new document” link will startup the corresponding client application (word, excel, ..) to create a new file based on the template which is set inside the content type.

Maybe some of you have come to a point where you would like to create a “New Document” link somewhere insite your page.
This can be done by calling some javascript functions.

Open infopath in client application

CoreInvoke('createNewDocumentWithRedirect','http://[siteurl]/FormServerTemplates/[templatename].xsn', '[FullUrlToLibrary]', 'SharePoint.OpenXmlDocuments.2', true, 'http://[siteurl]/_layouts/FormServer.aspx?XsnLocation=http://[siteurl]/FormServerTemplates/[templatename].xsn', false, 0);

Open infopath in browser (setting must be activated on the library)

CoreInvoke('createNewDocumentWithRedirect','http://[siteurl]/FormServerTemplates/[templatename].xsn', '[FullUrlToLibrary]', 'SharePoint.OpenXmlDocuments.2', true, 'http://[siteurl]/_layouts/FormServer.aspx?XsnLocation=http://[siteurl]/FormServerTemplates/[templatename].xsn', false, 1);

Open document in word

CoreInvoke('createNewDocumentWithProgID', '[FullUrlToWordTemplate]', '[FullUrlToLibrary]', 'SharePoint.OpenDocuments', false);

Open document in excel

CoreInvoke('createNewDocumentWithProgID', '[FullUrlToExcelTemplate]', '[FullUrlToLibrary]', 'SharePoint.OpenDocuments', false);

this function also works for opening excel:

CoreInvoke('createNewDocumentWithRedirect','[FullUrlToExcelTemplate]', '[FullUrlToLibrary]', 'SharePoint.OpenDocuments', false, '[siteurl]/_layouts/xlviewer.aspx?new=1', true, 0 );

Open document in powerpoint

CoreInvoke('createNewDocumentWithProgID', '[FullUrlToPowerpointTemplate]', '[FullUrlToLibrary]', 'SharePoint.OpenDocuments', false);

When you would like to use these code inside your custom application pages make sure to override its “OnPreRender” method

protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            ScriptLink.RegisterScriptAfterUI(this.Page, "core.js", true, false);
            ScriptLink.RegisterScriptAfterUI(this.Page, "CUI.js", false, true);
            ScriptLink.RegisterScriptAfterUI(this.Page, "SP.js", false, true);
        }

The reason for which we need to override the OnPreRender method is because we have to make sure the standard SharePoint .js files are loaded before our page is rendered.

Good luck !


Viewing all articles
Browse latest Browse all 2

Trending Articles