Free Support Forum - aspose.com

URL for the currently opened writer file (Java)

Hi, people.
I’m developing an extension using java works for Open Office Writer, and in some point I need to get the URL for the file that is currently opened in open office writer.
Any idea in how to get the path for the writer.odt files ?

This is what I get so far but it dose not work !


xmcf = m_xContext.getServiceManager();
desktop = xmcf.createInstanceWithContext(“com.sun.star.frame.Desktop”, m_xContext);
xDesktop = (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);
xDoc = xDesktop.getCurrentComponent();

xTextDocument = (XTextDocument) UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xDoc);
String dataDir = xTextDocument.getURL()+ File.separator;


//ExStart
//ExId:ExtractContentBasedOnStyles_Main
//ExSummary:Run queries and display results.
// Open the document.
Document doc = new Document(dataDir+ “Test.odt”);

We are using Aspose.Words v13.3.0.1 to extract words based on the styles. Here In this code, they used Document doc = new Document(dataDir+ “Test.odt”)so every file must be already exist and with the same path and name that is specified.

But we don’t want to specify the name and the path for the file we are working on, we need to make the ext work for any opened file in writer.


Hi there,


Thanks for your inquiry. Unfortunately, I have not understood your query. It would be great if you please share some more detail about your query.