How to Unlock the XML file created

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="color:black; background-color:white
<pre><span style="color:#0000ff Hi, [/code]
<pre><span style="color:#0000ff Here i am saving the Word Document in "Word XML 2003" format. I am able to save the XML in my machine, and able to format the xml created. But in client machine XML file is getting created, But i am [/code]
<pre><span style="color:#0000ff not able to format it. Some process is still using that XML. How can avoid this. [/code]
<pre><span style="color:#0000ff <br/>[/code]
<pre><span style="color:blue private <span style="color:blue void Btn_Convert_Click(<span style="color:blue object sender, EventArgs e)[/code]
<pre> {
<span style="color:blue string inputXmlPath = <span style="color:blue string.Empty;
<span style="color:blue try
{
<span style="color:green //Saving the Word Document in XML format
<span style="color:blue #region "Save Word Document as XML"

Microsoft.Office.Interop.Word.Application WordApp = <span style="color:blue new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document WordDoc = <span style="color:blue new Microsoft.Office.Interop.Word.Document();
<span style="color:blue object DocNoParam = Type.Missing;
<span style="color:blue object DocReadOnly = <span style="color:blue false;
<span style="color:blue object DocVisible = <span style="color:blue false;
<span style="color:blue object SaveToFormat = <span style="color:#a31515 "";

WordDoc = WordApp.Documents.Open(OpenFileDialog_Word.FileName.ToString(),
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocReadOnly,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocVisible,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam,
<span style="color:blue ref DocNoParam);
WordDoc.Activate();

SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXML;

<span style="color:blue string executablepath = Application.StartupPath;<span style="color:green //Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);////Application.ExecutablePath.Substring(0, Application.ExecutablePath.IndexOf("."));

inputXmlPath = executablepath + <span style="color:#a31515 @"Input.xml";
<span style="color:green //Deleting the file if exists
<span style="color:blue if (File.Exists(inputXmlPath))
{
File.Delete(inputXmlPath);
}

WordDoc.SaveAs(inputXmlPath, <span style="color:blue ref SaveToFormat, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam);
<span style="color:blue if (!File.Exists(inputXmlPath))
{
WordDoc.SaveAs(inputXmlPath, <span style="color:blue ref SaveToFormat, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam);
}
WordApp.Application.Quit(<span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam, <span style="color:blue ref DocNoParam);
WordDoc = <span style="color:blue null; WordApp = <span style="color:blue null;

[/code]

<br/>
<
Sudheer Kokirala<br/>

View the full article
 
Back
Top