I am using this code to convery an (.ODT) document into MS Word 2007 format.
andCode: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)); }
But while debugging at this point.....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(@"\", "/")); }
((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




Reply With Quote