Creating or Editing Office Application From SharePoint using Javascript

Have you ever felt the need to open office documents while working with SharePoint ??

The answer should definitely be yes…

As always let’s do it the sharepoint way…

SharePoint interanlly uses javascript functions to do this…these are

Open Document:

function RefreshOnFocus()
{
   window.location.href = window.location;
}

function CreateDoc()
{
   NewDocumentButton = new ActiveXObject("SharePoint.OpenDocuments.2");

   if (NewDocumentButton)
   {
      var strFileType = document.frmCreateDoc.CreateFileType.value;
      var strSaveLoc = document.frmCreateDoc.FileSaveLoc.value;

      if (NewDocumentButton.CreateNewDocument(strFileType, strSaveLoc))
      {
         window.onfocus = RefreshOnFocus;
      }
   }
}

Edit Document:

function EditDocWithProgID()
{
    EditDocumentButton = new ActiveXObject("SharePoint.OpenDocuments.2");

    if (EditDocumentButton)
    {
        var strDocument = document.frmEditDoc.EditFile.value;
        var varProgID = document.frmEditDoc.FileProgID.value;

        EditDocumentButton.EditDocument(strDocument, varProgID);
   }
}

Full reference can be found here
http://msdn.microsoft.com/en-us/library/ms454230(v=office.12).aspx

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.