Remove read-only from file

G

Guest

I need to make sure a file in my site's directory structure is not read-only.
The following code runs after I grant permission to ASPNET on the folder,
but the attribute is not removed (no exceptions thrown).

Dim filePath As String = "c:\inetpub\wwwroot\Test\fileName.xls"
If (File.GetAttributes(xlsTemplateFile) And FileAttributes.ReadOnly) =
FileAttributes.ReadOnly Then
File.SetAttributes(xlsTemplateFile, File.GetAttributes(xlsTemplateFile) Or
FileAttributes.ReadOnly)
End If
 
H

Herfried K. Wagner [MVP]

smay said:
I need to make sure a file in my site's directory structure is not
read-only.
The following code runs after I grant permission to ASPNET on the folder,
but the attribute is not removed (no exceptions thrown).

Dim filePath As String = "c:\inetpub\wwwroot\Test\fileName.xls"
If (File.GetAttributes(xlsTemplateFile) And FileAttributes.ReadOnly) =
FileAttributes.ReadOnly Then
File.SetAttributes(xlsTemplateFile, File.GetAttributes(xlsTemplateFile) Or
FileAttributes.ReadOnly)

Your code is currently /setting/ the read-only bit.

'Or' -> 'And Not'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top