Need a link to create a new document from an Office template?
Posted: 2012-02-04 Filed under: Document management, jQuery, Templates | Tags: jQuery, New document, Office template, SharePoint 2 CommentsHi everyone!
I found this blog post the other day and you can’t imagine the thrill I felt 🙂
This is something I have wanted to be able to do so many times and didn’t know how to, now I do and I want you to do as well.
As you can see (and read in the blog post) the saveLocation is set from where the template is located. I did a little change to route the save location to a place I decided. I also added a little change to wait until the page is loaded before the function is executed, always a good thing to do.
This is the original code:
<script type="text/javascript" src="/_layouts/jquery.min.js"></script> <script type="text/javascript"> $( function () { $("a[href$='.dot'], a[href$='.dotx'], a[href$='.xlt'], a[href$='.xltx']").attr("onclick", "").click( function () { saveLocation = $(this).attr("href").split("/").slice(0, -2).join("/") createNewDocumentWithProgID(window.location.protocol + '//' + window.location.host + $(this).attr("href"), window.location.protocol + '//' + window.location.host + saveLocation, 'SharePoint.OpenDocuments', false) return false }) }) </script>
and this is my modified one with a hard coded save location:
<script type="text/javascript" src="/Style%20Library/Scripts/jquery-1.4.4.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("a[href$='.dot'], a[href$='.dotx'], a[href$='.xlt'], a[href$='.xltx']").attr("onclick", "").click( function () { createNewDocumentWithProgID(window.location.protocol + '//' + window.location.host + $(this).attr("href"), makeAbsUrl('http://MyIntranet/sitename/sitename/librar%20name'), 'SharePoint.OpenDocuments', false) return false }) }) </script>
Here is another one that prompts to save the document in the logged in users local Document library.
<script type="text/javascript"> $(document).ready(function(){ $("a[href$='.dot'], a[href$='.dotx'], a[href$='.xlt'], a[href$='.xltx']").attr("onclick", "").click( function () { createNewDocumentWithProgID(window.location.protocol + '//' + window.location.host + $(this).attr("href"),'C:\Users\{login}\Documents' , 'SharePoint.OpenDocuments', false) return false }) }) </script>
As always when we are working with jQuery you have to make sure that you reference the location of that .js-file
CU
/Niax