I have a number of word documents I am converting. Everything is going great until I get a file that is read only. In this case I get a Save As prompt.
Is there any way to open the file in read/write format? I should have admin privileges so access isn't an issue.
I'm using VB.net to open the files. More specifically
doc = word.Documents.Open(path, Type.Missing, False, Ty开发者_如何学JAVApe.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
To open a read-only file you need to set that attribute to false:
string path = "C:\\test.txt";
FileInfo info = new FileInfo(path);
info.IsReadOnly = false;
StreamWriter writer = new StreamWriter(path);
writer.WriteLine("This is an example.");
writer.Close();
info.IsReadOnly=true;
This was an example but I'm sure it will work with word files.
EDIT:
VB.NET equivalent:
Dim path As String = "C:\test.txt"
Dim info As FileInfo = New FileInfo(path)
info.IsReadOnly = False
Dim writer As StreamWriter = New StreamWriter(path)
writer.WriteLine("This is an example.")
writer.Close()
info.IsReadOnly = True
Before you open the file, check its Attributes with a FileInfo class.
If the Attributes property contains FileAttributes.ReadOnly, change it and the file will no longer be read-only.
精彩评论