Apache OpenOffice (AOO) Bugzilla – Issue 72979
exception without description when saving document with same filename
Last modified: 2013-02-24 21:06:58 UTC
Hi! I'm receiving exception without description when trying to save opened document. I'm using .NET 2.0 and uno with OO 2.1 I can workaround this by saving to another filename.. ("temp" in commented line) try { XStorable xSave = (XStorable)xTextDocument; //xSave.store(); PropertyValue[] pv = new PropertyValue[2]; pv[0] = new PropertyValue(); pv[0].Name = "FilterName"; pv[0].Value = new uno.Any("StarOffice XML (Writer)"); pv[1] = new PropertyValue(); pv[1].Name = "Overwrite"; pv[1].Value = new uno.Any("true"); string fajl=xSave.getLocation(); xSave.storeToURL(fajl.Replace('\\', '/'), pv); //xSave.storeToURL(fajl.Replace('\\', '/') + "temp", pv); } catch(unoidl.com.sun.star.uno.Exception ex) { Console.WriteLine(ex.ToString()); return false; } xSave.store() and xSave.storeToURL(xSave.getLocation(), pv); shows the same behaviour
i will check this asap
accepted for evaluation
it is true that the thrown exception contains no description but that is another topic (inconsistent error handling ...) But i would expect that you simply use the API wrong here. What do you want to achieve? First take a look into the description of XStorable. You can't use store() on a new document before you have stored it to an URL. getLocation() on a new document retunrs an empty string and can cause a problem as well -> depending how it is used. When i create a new document, use storeAsUrl or storeToUrl (see the decription for the difference) and use later store() or again storeToUrl everything works as expected and no exception is thrown.
closed
I'm not trying to store new document. I'm trying to store document which I opened. I used xComponent = aLoader.loadComponentFromURL("file:///" + fajl, "_blank", 0, pv); xTextDocument = (XTextDocument)xComponent; to open existing odf file. I changed it. I tried to save it with same filename.
it works for me with a loaded document as well. I don't know what you are doing. Although storeToURL with the same URL as the loaded document makes not really sense but it works. The document on the disk is changed and the document in the office has still the status "changed". But when i close the document without saving and load it again i got the latest changes from storeToURL. I got no exception!!
Ok, here is simple POF It breaks on line xSave.storeToURL or on xSave.store() using System; using System.Collections.Generic; using System.Text; using unoidl.com.sun.star.util; using unoidl.com.sun.star.frame; using unoidl.com.sun.star.beans; using unoidl.com.sun.star.text; using unoidl.com.sun.star.lang; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { OpenOfficeWriter oo = new OpenOfficeWriter(); oo.LoadDoc(@"C:\example.odt"); oo.SaveDoc(); } } internal class OpenOfficeWriter { internal unoidl.com.sun.star.uno.XComponentContext xLocalContext; internal unoidl.com.sun.star.lang.XMultiServiceFactory xRemoteFactory; internal XComponentLoader aLoader; internal XComponent xComponent; internal XTextDocument xTextDocument; internal OpenOfficeWriter() { } public bool LoadDoc(string fajl) { xLocalContext = uno.util.Bootstrap.bootstrap(); xRemoteFactory = (XMultiServiceFactory)xLocalContext.getServiceManager(); aLoader = (XComponentLoader)xRemoteFactory.createInstance("com.sun.star.frame.Desktop"); xComponent = aLoader.loadComponentFromURL("file:///" + fajl, "_blank", 0, new PropertyValue[0]); xTextDocument = (XTextDocument)xComponent; return true; } public bool SaveDoc() { XStorable xSave = (XStorable)xTextDocument; //xSave.store(); PropertyValue[] pv = new PropertyValue[2]; pv[0] = new PropertyValue(); pv[0].Name = "FilterName"; pv[0].Value = new uno.Any("StarOffice XML (Writer)"); pv[1] = new PropertyValue(); pv[1].Name = "Overwrite"; pv[1].Value = new uno.Any("true"); string fajl = xSave.getLocation(); xSave.storeToURL(fajl.Replace('\\', '/'), pv); return true; } } }
your example works fine for me. But of course you don't prepare a valid URL in LoadDoc. Your input is "c:\example.odt" and you don't convert the backslash. However, the example works fine for me and i got no exception. I tested the example with an office based on a m196 source tree and a .NET 2.0 framework. I don't expect that this makes the difference but you can at least check it with a newer development build of the office.