locked
C# Word - Mark as final RRS feed

  • Question

  • Hi,

    I want to make Microsoft word doc as Mark as final (this option available under office->Prepare option in word) using C# or VB.NET.

    any input will be highly appreciated

    Regards
    Sumit
    Tuesday, October 28, 2008 11:49 AM

Answers

  • Here is the code, please use as you want, currently in form load event, and do not forget to add reference to Microsoft.Office.Interop.Word from project - Add reference:

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 
    using Word = Microsoft.Office.Interop.Word; 
    namespace WindowsApplication1 
        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            } 
     
            private void Form1_Load(object sender, EventArgs e) 
            { 
                Word.Application wordnew Word.Application(); 
               
                Object missing = Type.Missing; 
                Object btrue = true; 
                Object bfalse = false; 
                Object filename = "I:\\1\\test1.docx"
     
                Microsoft.Office.Interop.Word.Document oWordDoc = word.Documents.Open(ref filename, ref missing, ref  
     
                      bfalse, ref missing, ref missing, ref missing, ref  
     
                      missing, ref missing, ref missing, ref missing, ref 
     
                      missing, ref bfalse, ref missing, ref missing, ref 
     
                      missing, ref missing); 
     
                oWordDoc.Final = true
     
                oWordDoc.Close(ref bfalse, ref missing, ref missing); 
     
     
            } 
        } 




    Arjun Paudel
    • Marked as answer by Sumitd Wednesday, October 29, 2008 8:12 AM
    Tuesday, October 28, 2008 2:27 PM

All replies

  • Here is the code, please use as you want, currently in form load event, and do not forget to add reference to Microsoft.Office.Interop.Word from project - Add reference:

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 
    using Word = Microsoft.Office.Interop.Word; 
    namespace WindowsApplication1 
        public partial class Form1 : Form 
        { 
            public Form1() 
            { 
                InitializeComponent(); 
            } 
     
            private void Form1_Load(object sender, EventArgs e) 
            { 
                Word.Application wordnew Word.Application(); 
               
                Object missing = Type.Missing; 
                Object btrue = true; 
                Object bfalse = false; 
                Object filename = "I:\\1\\test1.docx"
     
                Microsoft.Office.Interop.Word.Document oWordDoc = word.Documents.Open(ref filename, ref missing, ref  
     
                      bfalse, ref missing, ref missing, ref missing, ref  
     
                      missing, ref missing, ref missing, ref missing, ref 
     
                      missing, ref bfalse, ref missing, ref missing, ref 
     
                      missing, ref missing); 
     
                oWordDoc.Final = true
     
                oWordDoc.Close(ref bfalse, ref missing, ref missing); 
     
     
            } 
        } 




    Arjun Paudel
    • Marked as answer by Sumitd Wednesday, October 29, 2008 8:12 AM
    Tuesday, October 28, 2008 2:27 PM
  • Thanx for the reply.

    Its working fine. But i am getting messge "This document will be marked as final and then saved". How can we make this message in silent?

    Wednesday, October 29, 2008 5:32 AM
  • I forgot to tell you, I could not do that as well, didnt find any documentation re that, its a boolean value and accepts true false, no other parameter

    In MSDN:

    Returns or sets a Boolean that indicates whether a document is final. Read/write.

    Syntax

    expression.Final

    expression   An expression that returns a Document object.

    Remarks

    True marks the document as final, notifies recipients (if any) that the document is final, and sets the document to read-only.



    Arjun Paudel
    Wednesday, October 29, 2008 5:44 AM
  • Can you please provide me the link of word developer reference of final?
    Wednesday, October 29, 2008 6:55 AM
  • http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.document.final.aspx
    Arjun Paudel
    Wednesday, October 29, 2008 6:59 AM
  • Got the link.
    Wednesday, October 29, 2008 7:01 AM
  • Please let me know if you get any solution to make it silent. I am also trying to find it out. If i get the solution i will post it here.

    Wednesday, October 29, 2008 7:49 AM
  • Try this:

    http://msdn.microsoft.com/en-us/library/aa192495%28v=office.11%29.aspx

    it is DisplayAlert property ... Please try and tell me, for me it worked fine.

    Unfortunately ... suddenly .... not working!!

    • Proposed as answer by Sanousy Howari Wednesday, March 14, 2012 10:38 AM
    • Edited by Sanousy Howari Monday, March 19, 2012 8:08 PM status update
    • Unproposed as answer by Sanousy Howari Monday, March 19, 2012 8:08 PM
    Monday, February 27, 2012 7:09 PM