3

I'd like to save a TextDocument created through OpenOffice.org UNO to a file on the disk. What is the best way to do this?

Edit: This is the C# code that I ended up using. document is an XTextDocument.

protected void Save (string path)
{
    string url = "file://" + path;
    PropertyValue [] propertyValues = {
        new PropertyValue {
            Name = "FilterName",
            Value = new Any ("writer8")
        }
    };
    ((XStorable) document).storeAsURL (url, propertyValues);
}
Matthew
  • 28,056
  • 26
  • 104
  • 170
  • I'm working in C#, but if you answer in a different language, I can translate it to C#. – Matthew Jan 07 '10 at 19:06
  • 3
    Be careful what you wish for - ++++[>+++++<-]>[<+++++>-]+<+[>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+>>>+[[-]++++++> >>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]<<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++ >[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-] – Hamish Grubijan Jan 07 '10 at 19:14
  • 1
    Didn't know OOo was scriptable in BF. – Mirko N. Jan 07 '10 at 19:24

1 Answers1

2

Use XStorable.storeToURL() (or storeAsURL).

Edit: You need to pass a FilterName with the output format. Example (in Python 'cause that's simpler):

properties = ( PropertyValue('FilterName', 0, 'writer8', 0), )
document.storeToURL('file:///path/to/document.odt', properties)
Mirko N.
  • 10,537
  • 6
  • 38
  • 37
  • `storeToURL ()` and `storeAsURL ()` require 2 parameters, even though the documentation says the second is optional. I tried passing `null` as the second, but I get an IOException. I'm looking around the documentation now, but do you know how to fix this? If I can figure out how to set the default URL of the document, I can just use the `store ()` method and avoid the whole issue. – Matthew Jan 07 '10 at 19:28
  • Thanks, this works perfectly. I added the C# version of this code to my question. – Matthew Jan 07 '10 at 20:01