Rals V

Rals V

  • NA
  • 3
  • 0

Unable to unprotect word file using C#

Jul 24 2009 11:31 AM
//code Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); object nullobj = System.Reflection.Missing.Value; string pass = "abcd1234"; object password = pass; object FName = fileName; Microsoft.Office.Interop.Word.Document aDoc = null; wordApp.Visible = false; aDoc = wordApp.Documents.Open(ref FName, ref nullobj, ref nullobj, ref nullobj, ref password, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); aDoc.Activate(); if (aDoc.HasPassword) aDoc.Password = null; if (aDoc.ProtectionType != wdProtectionType.wdNoProtection) aDoc.Unprotect(ref password); aDoc.SaveAs(ref FName, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); aDoc.Close(ref nullobj, ref nullobj, ref nullobj); } //code Hi All, I use this above code to remove the password and unprotect my word document. But for some strange reason it works fine on some files but does not remove the password protection on some. Is there something I am missing? Thanks in advance. Rals Apologies for the wierd display

Answers (3)