Hi All,
I took two buttons and one text box and wrote the code for transformation.
It's executed, but after selecting the document it displayed two pop up messages...
1.(File in use)<br />
Do you want to<br />
Open a read only copy<br />
Create a local copy and merge changes later<br />
Receive notification when the original copy is available.<br />
After selecting read only copy, it will display another popup msg
2.Convert file
My target is when I select the document, directly it will transfer to another file.no pop up message displayed.
Please help me.
Using word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
namespace saveas
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Open File";
openFileDialog1.Filter = "All Files|*.*";
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName != "")
{
textBox1.Text = openFileDialog1.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
if ((!string.IsNullOrWhiteSpace(textBox1.Text)))
{
object filepath = "C:\\Myfile";
object FileName = "Myfile.xml";
object FileFormat =word.WdSaveFormat.wdFormatXML;
object Commentators = false;
object AddToRecentFiles = true;
object ReadOnlyRecommended = false;
object EmbedTrueTypeFonts = false;
object SaveNativePictureFormat = true;
object SaveFormsData = true;
object SaveAsAOCELetter = false;
object Encoding = Office.MsoEncoding.msoEncodingUTF8;
object InsertLineBreaks =false;
object AllowSubstitutions = false;
object LineEnding = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
object AddBiDiMarks = false;
object missing = string.Empty;
Microsoft.Office.Interop.Word.Application test = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc = test.Documents.Open(openFileDialog1.FileName, true);
wordDoc.SaveAs(ref FileName, ref FileFormat, ref LockComments,
ref missing, ref AddToRecentFiles, ref missing,
ref ReadOnlyRecommended, ref EmbedTrueTypeFonts,
ref SaveNativePictureFormat, ref SaveFormsData,
ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks,ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc);
}
}
}
}