Env:Windows 10 64 bit, Visual Studio express 2013. I've installed microsoft office 2013 and 2003. And already add Microsoft Office 11.0 object library
and Microsoft Word 11.0 object library
references.But doesnot work.
I've tried that if I change Microsoft Word 11.0 object library
to Microsoft Word 15.0 object library
and everything is OK.But I need to work for word 2003,so, what should I do?
code:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
namespace readDOC {
class Program {
static void Main(string[] args) {
string cd = Directory.GetCurrentDirectory();
Word.Application word = new Word.Application();
List<string> dirs = new List<string>();
foreach (string dir in Directory.GetFiles(@".", "*.doc?")) {
if (dir.IndexOf('~') == -1) {
dirs.Add(cd + dir.Substring(1));
}
}
foreach (string fn in dirs) {
Word.Document docs = word.Documents.Open(fn);
try {
docs.Protect(Word.WdProtectionType.wdAllowOnlyReading);
Console.WriteLine(@"OK:{0}.", fn);
} catch (Exception e) {
Console.WriteLine(@"NOT OK:{0}.", fn);
} finally {
docs.Close();
}
}
word.Quit();
Console.WriteLine("Press any key to finish");
Console.ReadLine();
}
}
}