Home All Groups Group Topic Archive Search About

Remove read-only from file

Author
27 Jun 2005 1:41 PM
smay
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

Author
27 Jun 2005 2:17 PM
Herfried K. Wagner [MVP]
"smay" <s***@discussions.microsoft.com> schrieb:
>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'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>