| View previous topic :: View next topic |
| Author |
Message |
maverick786us General User

Joined: 11 Jul 2012 Posts: 26
|
Posted: Fri Jul 13, 2012 1:24 am Post subject: 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;
}
}
|
| Code: |
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));
}
|
| 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.....
| Code: |
((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 |
|
| Back to top |
|
 |
maverick786us General User

Joined: 11 Jul 2012 Posts: 26
|
Posted: Sun Jul 15, 2012 11:53 pm Post subject: |
|
|
OK I am able to resolve this problem my making slight change with the code
| Code: |
//destinationFile = "file:///C:/Documents and Settings/User/My Documents/Harry_Home_Bill_Receip.doc";
string destinationFile1 = destinationFile;
destinationFile1 = destinationFile1.Replace(".odt", ".doc");
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);
XStorable xcomponent1 = (xComponent) as XStorable;
xcomponent1.storeToURL(destinationFile1, propertyValues);
|
It is successfully getting converted. But there is a slight problem. In 32-bit windows XP its working fine. But in 64-bit Windows 7 after the conversion it looses its input fields |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|