Issue 72979 - exception without description when saving document with same filename
Summary: exception without description when saving document with same filename
Status: CLOSED NOT_AN_OOO_ISSUE
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All Windows XP
: P3 Trivial
Target Milestone: ---
Assignee: jsc
QA Contact: issues@api
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-28 19:18 UTC by rpavelic
Modified: 2013-02-24 21:06 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description rpavelic 2006-12-28 19:18:02 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
Comment 1 jsc 2006-12-29 10:01:24 UTC
i will check this asap
Comment 2 jsc 2007-01-12 09:58:18 UTC
accepted for evaluation
Comment 3 jsc 2007-01-15 11:02:31 UTC
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.
Comment 4 jsc 2007-01-15 11:02:55 UTC
closed
Comment 5 rpavelic 2007-01-15 16:08:59 UTC
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.
Comment 6 jsc 2007-01-15 17:02:54 UTC
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!!

Comment 7 rpavelic 2007-01-15 17:27:05 UTC
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;
        }


    }

}
Comment 8 jsc 2007-01-16 08:54:55 UTC
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.
Comment 9 jsc 2007-01-22 15:39:59 UTC
closed