-
July 13th, 2012, 01:05 AM
#1
Problem while converting the document
I am using this code to convery an (.ODT) document into MS Word 2007 format.
Code:
private void Browse_Click(object sender, EventArgs e)
{
// Displays an OpenFileDialog so the user can select a Cursor.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Open Office Document|*.odt";
openFileDialog1.Title = "Select an Open Office Document";
// Show the Dialog.
// If the user clicked OK in the dialog and
// a .CUR file was selected, open it.
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
file = txtODTFile.Text = openFileDialog1.FileName;
}
} private void Convert_Click(object sender, EventArgs e)
{
unoidl.com.sun.star.uno.XComponentContext xLocalContext = uno.util.Bootstrap.bootstrap();
unoidl.com.sun.star.lang.XMultiServiceFactory xRemoteFactory =
(unoidl.com.sun.star.lang.XMultiServiceFactory)xLocalContext.getServiceManager();
XComponentLoader aLoader = (XComponentLoader)xRemoteFactory.createInstance("com.sun.star.frame.Desktop");
XComponent xComponent = initDocument(aLoader, PathConverter(file), "_blank");
saveDocument(xComponent, file, PathConverter(file));
}
and
Code:
private static XComponent initDocument(XComponentLoader aLoader, string file, string target)
{
try
{
PropertyValue[] openProps = new PropertyValue[1];
openProps[0] = new PropertyValue();
openProps[0].Name = "Hidden";
openProps[0].Value = new uno.Any(true);
XComponent xComponent = aLoader.loadComponentFromURL(file, target, 0, openProps);
return xComponent;
}
catch (System.Exception Exp)
{
MessageBox.Show(Exp.Message);
return null;
}
finally
{
aLoader = null;
file = null;
target = null;
}
}
private static void saveDocument(XComponent xComponent, string sourceFile, string destinationFile)
{
PropertyValue[] propertyValues = new PropertyValue[1];
propertyValues[0] = new PropertyValue();
propertyValues[0].Name = "Overwrite";
propertyValues[0].Value = new uno.Any("MS Word 2007");
((XStorable)xComponent).storeToURL(destinationFile, propertyValues);
}
private static string PathConverter(string file)
{
if (file == null || file.Length == 0)
throw new NullReferenceException("Null or empty file passed to the office");
file = file.Replace(".odt",".doc");
return String.Format("file:///{0}", file.Replace(@"\", "/"));
}
But while debugging at this point.....
((XStorable)xComponent).storeToURL(destinationFile, propertyValues);
It is throwing exception stating that "An unhandled exception of type 'unoidl.com.sun.star.task.ErrorCodeIOException' occurred in mscorlib.dll". How can i over come this problem??
Thanks in Advance
-
August 25th, 2012, 08:09 AM
#2
Re: Problem while converting the document
The error you are getting is specific to the component/API you are using to do the conversion. Your best chance of getting a meaningful answer is to ask your question in a forum specific to the component (like at the developer's site). At the very lest, you should title your question something like "IOError When using _____ API to convert ODT to DOCX." You need to find someone who is familiar with that API. Good luck!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|