Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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);
}

             }

   }
}
Posted
Updated 16-May-11 21:35pm
v3
Comments
Dalek Dave 17-May-11 3:36am    
Edited for Grammar and Readability.
Mario Majčica 18-May-11 2:42am    
Try this http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/e56ee461-b9e0-43a2-a978-4276293d8b9b

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900