none
How to get the name of the file using Office 2013 Javascript API RRS feed

  • Question

  • I am creating a Office Task Pane app and running it using MS Word 2013. As i run the app it opened a task pane in Word with a document named "Document1.docx". How can i get this file name "Document1.docx" using Office 2013 Javascript API??
    Tuesday, March 5, 2013 1:23 PM

Answers

  • Hello Pomka one thing you can try is to use the Office.context.document.url property which depending on where you opened the file from you can actually get either:

    1. if you opened from a document library, you'll get the full URL of the document including the file name.

    2. if you opened the file from your local drive it will give you the full path of the document (including the file name as well)

    That said,  this API is designed to get the file name from existing documents, but it will return null if this is a new document (as the document does not have a location at this point)

    it would be great to know more details about your scenario and see how we can improve this API in the future.

    another caveat of this property is that it does not refresh the document name in case you save the doc with a different name, its filled when the library is initialized, but next time you open the document it will be refreshed.



    Wednesday, March 6, 2013 11:02 AM
    Moderator

All replies

  • As far as i know, there is no this API to get the name.  You can look through the JavaScript API for Office from the below link:

    http://msdn.microsoft.com/en-us/library/fp142185.aspx 

    Wednesday, March 6, 2013 8:12 AM
  • Is there any other method with that i can get the file name of a word document within an Office Task Pane app?
    Wednesday, March 6, 2013 8:47 AM
  • I agree with Learning hard. By no means could you do that. This is the limitation of App for Office, I suppose. It cannot replace Office PIA.


    with regards, Yuri

    Wednesday, March 6, 2013 9:11 AM
  • Hello Pomka one thing you can try is to use the Office.context.document.url property which depending on where you opened the file from you can actually get either:

    1. if you opened from a document library, you'll get the full URL of the document including the file name.

    2. if you opened the file from your local drive it will give you the full path of the document (including the file name as well)

    That said,  this API is designed to get the file name from existing documents, but it will return null if this is a new document (as the document does not have a location at this point)

    it would be great to know more details about your scenario and see how we can improve this API in the future.

    another caveat of this property is that it does not refresh the document name in case you save the doc with a different name, its filled when the library is initialized, but next time you open the document it will be refreshed.



    Wednesday, March 6, 2013 11:02 AM
    Moderator
  • Thanks Juan Balmori.

    You make my day. Thank you so much. I have already checked that "Office.context.document.url" property, but at that time, it was returning empty string. But as you mentioned that for a newly created document it returns, empty string, I tried my app for a existing document and then it start returning the file path.

    Thanks once again.


    Thursday, March 7, 2013 7:59 AM
  •  I am building taskpane add in using angular. The same function is returning error bcoz it is loaded from browser. Is there anyway can we handle the error if the app runs from the browser ?
    Monday, July 8, 2019 3:35 AM