File Security Question 
Author Message
 File Security Question

I have a very simple question...

I have a VB.Net program that is attempting to delete a file using the
following instruction:

    File.Delete(strFileSpec)

When I attempt to execute this instruction, I get an error that says "Access
to the Path <strFileSpec> is Denied".

I have checked all the privileges on the folder and the file and set them so
that "Everyone" have full access.  I can't figure out what's preventing
VB.Net from deleting this file.

Any ideas?

Thanks,

Chuck



Mon, 28 Nov 2005 00:38:06 GMT  
 File Security Question
Is it open by any program? Do you create the file in your code, then try to
delete it? Because, you might not have closed the file if you are messing
about with it.

--
Happy to help,
-- Tom Spink

Please respond to the newsgroup,
so all can benefit.

One Day,

Quote:
> I have a very simple question...

> I have a VB.Net program that is attempting to delete a file using the
> following instruction:

>     File.Delete(strFileSpec)

> When I attempt to execute this instruction, I get an error that says
"Access
> to the Path <strFileSpec> is Denied".

> I have checked all the privileges on the folder and the file and set them
so
> that "Everyone" have full access.  I can't figure out what's preventing
> VB.Net from deleting this file.

> Any ideas?

> Thanks,

> Chuck



Mon, 28 Nov 2005 01:54:38 GMT  
 File Security Question
Hi Tom...it's not open by any other progam and my program didn't create it.

Any other ideas?

Thanks,

Chuck


Quote:
> Is it open by any program? Do you create the file in your code, then try
to
> delete it? Because, you might not have closed the file if you are messing
> about with it.

> --
> Happy to help,
> -- Tom Spink

> Please respond to the newsgroup,
> so all can benefit.

> One Day,


> > I have a very simple question...

> > I have a VB.Net program that is attempting to delete a file using the
> > following instruction:

> >     File.Delete(strFileSpec)

> > When I attempt to execute this instruction, I get an error that says
> "Access
> > to the Path <strFileSpec> is Denied".

> > I have checked all the privileges on the folder and the file and set
them
> so
> > that "Everyone" have full access.  I can't figure out what's preventing
> > VB.Net from deleting this file.

> > Any ideas?

> > Thanks,

> > Chuck



Mon, 28 Nov 2005 01:55:47 GMT  
 File Security Question
How about the ownership of the file? Is that set to the user executing the
application (or the user context the app is running in)

--
Happy to help,
-- Tom Spink

Please respond to the newsgroup,
so all can benefit.

One Day,

Quote:
> Hi Tom...it's not open by any other progam and my program didn't create
it.

> Any other ideas?

> Thanks,

> Chuck



> > Is it open by any program? Do you create the file in your code, then try
> to
> > delete it? Because, you might not have closed the file if you are
messing
> > about with it.

> > --
> > Happy to help,
> > -- Tom Spink

> > Please respond to the newsgroup,
> > so all can benefit.

> > One Day,


> > > I have a very simple question...

> > > I have a VB.Net program that is attempting to delete a file using the
> > > following instruction:

> > >     File.Delete(strFileSpec)

> > > When I attempt to execute this instruction, I get an error that says
> > "Access
> > > to the Path <strFileSpec> is Denied".

> > > I have checked all the privileges on the folder and the file and set
> them
> > so
> > > that "Everyone" have full access.  I can't figure out what's
preventing
> > > VB.Net from deleting this file.

> > > Any ideas?

> > > Thanks,

> > > Chuck



Mon, 28 Nov 2005 02:16:38 GMT  
 File Security Question
I found the problem...the "ReadOnly" attribute of the file was set....It
would have been nice if the error message had just told me that instead of
just saying "Access is Denied"

Thanks,


Quote:
> How about the ownership of the file? Is that set to the user executing the
> application (or the user context the app is running in)

> --
> Happy to help,
> -- Tom Spink

> Please respond to the newsgroup,
> so all can benefit.

> One Day,


> > Hi Tom...it's not open by any other progam and my program didn't create
> it.

> > Any other ideas?

> > Thanks,

> > Chuck



> > > Is it open by any program? Do you create the file in your code, then
try
> > to
> > > delete it? Because, you might not have closed the file if you are
> messing
> > > about with it.

> > > --
> > > Happy to help,
> > > -- Tom Spink

> > > Please respond to the newsgroup,
> > > so all can benefit.

> > > One Day,


> > > > I have a very simple question...

> > > > I have a VB.Net program that is attempting to delete a file using
the
> > > > following instruction:

> > > >     File.Delete(strFileSpec)

> > > > When I attempt to execute this instruction, I get an error that says
> > > "Access
> > > > to the Path <strFileSpec> is Denied".

> > > > I have checked all the privileges on the folder and the file and set
> > them
> > > so
> > > > that "Everyone" have full access.  I can't figure out what's
> preventing
> > > > VB.Net from deleting this file.

> > > > Any ideas?

> > > > Thanks,

> > > > Chuck



Mon, 28 Nov 2005 02:27:56 GMT  
 File Security Question
Here's the final fix to this problem just in case anyone else runs into
it...I had to check to see if the "ReadOnly" attribute of the file was set
and clear it before I deleted it.  I just created a little Sub called
"DeleteFile" to do that:
Friend Sub DeleteFile(ByVal FileSpec As String)

    If (File.GetAttributes(FileSpec) And FileAttributes.ReadOnly) =
FileAttributes.ReadOnly Then

            File.SetAttributes(FileSpec, FileAttributes.Normal)

    End If

    File.Delete(FileSpec)

End Sub

This did the job for me...this was an elusive error because the error
message sounded like it was a security issue...it took a little while to
remember that trying to delete a "readonly" file will also cause an error.

Chuck


Quote:
> I have a very simple question...

> I have a VB.Net program that is attempting to delete a file using the
> following instruction:

>     File.Delete(strFileSpec)

> When I attempt to execute this instruction, I get an error that says
"Access
> to the Path <strFileSpec> is Denied".

> I have checked all the privileges on the folder and the file and set them
so
> that "Everyone" have full access.  I can't figure out what's preventing
> VB.Net from deleting this file.

> Any ideas?

> Thanks,

> Chuck



Mon, 28 Nov 2005 02:57:10 GMT  
 File Security Question
Hi Chuck

I also ran into the same problem. The problem I'm having is that the file
can have a attribute set as A, or AH or AHR, or AR. Is there a easy way of
checking just for R and deleting it?


Quote:
> Here's the final fix to this problem just in case anyone else runs into
> it...I had to check to see if the "ReadOnly" attribute of the file was set
> and clear it before I deleted it.  I just created a little Sub called
> "DeleteFile" to do that:
> Friend Sub DeleteFile(ByVal FileSpec As String)

>     If (File.GetAttributes(FileSpec) And FileAttributes.ReadOnly) =
> FileAttributes.ReadOnly Then

>             File.SetAttributes(FileSpec, FileAttributes.Normal)

>     End If

>     File.Delete(FileSpec)

> End Sub

> This did the job for me...this was an elusive error because the error
> message sounded like it was a security issue...it took a little while to
> remember that trying to delete a "readonly" file will also cause an error.

> Chuck



> > I have a very simple question...

> > I have a VB.Net program that is attempting to delete a file using the
> > following instruction:

> >     File.Delete(strFileSpec)

> > When I attempt to execute this instruction, I get an error that says
> "Access
> > to the Path <strFileSpec> is Denied".

> > I have checked all the privileges on the folder and the file and set
them
> so
> > that "Everyone" have full access.  I can't figure out what's preventing
> > VB.Net from deleting this file.

> > Any ideas?

> > Thanks,

> > Chuck



Mon, 28 Nov 2005 17:17:13 GMT  
 File Security Question
Hi, the attributes are flags, so they are like this:

(Note this is an example)

ReadOnly = 1    = 0001
Archive = 2        = 0010
Hidden = 4        = 0100
System = 8        = 1000

So, to check for Hidden, we do this (pseudocode):

If (FileAttributes And Hidden) = Hidden Then
    ' Hidden Is Set, so remove it with this code:
    NewAttributes = FileAttributes And Not Hidden
End If

So, say the file was readonly, hidden and system, the file attributes would
be 1101 (13)

ATTR And Hidden = Hidden
1101 And 0100 = 0100, So Hidden is set

ATTR And (Not Hidden)
1101 And 1011 = 1001

Hidden has been removed.

In VB.NET:

' If hidden is set, then it is removed:
If (File.GetAttributes(FileSpec) And FileAttributes.Hidden) =
FileAttributes.Hidden Then
    File.SetAttributes(FileSpec, File.GetAttributes(FileSpec) And Not
FileAttributes.Hidden)
End If

--
Happy to help,
-- Tom Spink

Please respond to the newsgroup,
so all can benefit.

One Day,

Quote:
> Hi Chuck

> I also ran into the same problem. The problem I'm having is that the file
> can have a attribute set as A, or AH or AHR, or AR. Is there a easy way of
> checking just for R and deleting it?



> > Here's the final fix to this problem just in case anyone else runs into
> > it...I had to check to see if the "ReadOnly" attribute of the file was
set
> > and clear it before I deleted it.  I just created a little Sub called
> > "DeleteFile" to do that:
> > Friend Sub DeleteFile(ByVal FileSpec As String)

> >     If (File.GetAttributes(FileSpec) And FileAttributes.ReadOnly) =
> > FileAttributes.ReadOnly Then

> >             File.SetAttributes(FileSpec, FileAttributes.Normal)

> >     End If

> >     File.Delete(FileSpec)

> > End Sub

> > This did the job for me...this was an elusive error because the error
> > message sounded like it was a security issue...it took a little while to
> > remember that trying to delete a "readonly" file will also cause an
error.

> > Chuck



> > > I have a very simple question...

> > > I have a VB.Net program that is attempting to delete a file using the
> > > following instruction:

> > >     File.Delete(strFileSpec)

> > > When I attempt to execute this instruction, I get an error that says
> > "Access
> > > to the Path <strFileSpec> is Denied".

> > > I have checked all the privileges on the folder and the file and set
> them
> > so
> > > that "Everyone" have full access.  I can't figure out what's
preventing
> > > VB.Net from deleting this file.

> > > Any ideas?

> > > Thanks,

> > > Chuck



Mon, 28 Nov 2005 20:00:42 GMT  
 File Security Question

Quote:
> >Is there a easy way of checking just for R and deleting it?

Hi Chris,

The code I posted in my response does essentially that.  Here it is again:

Friend Sub DeleteFile(ByVal FileSpec As String)

    If (File.GetAttributes(FileSpec) And FileAttributes.ReadOnly) =  FileAttributes.ReadOnly Then

             File.SetAttributes(FileSpec, FileAttributes.Normal)

    End If

    File.Delete(FileSpec)

End Sub

I think this method is simpler than manipulating the bits.  Someone might argue that my method destroys the state of the other bits, but if you're going to delete the file anyway, why does it matter?

Chuck

Quote:

> Hi Chuck

> I also ran into the same problem. The problem I'm having is that the file
> can have a attribute set as A, or AH or AHR, or AR. Is there a easy way of
> checking just for R and deleting it?



> > Here's the final fix to this problem just in case anyone else runs into
> > it...I had to check to see if the "ReadOnly" attribute of the file was set
> > and clear it before I deleted it.  I just created a little Sub called
> > "DeleteFile" to do that:
> > Friend Sub DeleteFile(ByVal FileSpec As String)

> >     If (File.GetAttributes(FileSpec) And FileAttributes.ReadOnly) =
> > FileAttributes.ReadOnly Then

> >             File.SetAttributes(FileSpec, FileAttributes.Normal)

> >     End If

> >     File.Delete(FileSpec)

> > End Sub

> > This did the job for me...this was an elusive error because the error
> > message sounded like it was a security issue...it took a little while to
> > remember that trying to delete a "readonly" file will also cause an error.

> > Chuck



> > > I have a very simple question...

> > > I have a VB.Net program that is attempting to delete a file using the
> > > following instruction:

> > >     File.Delete(strFileSpec)

> > > When I attempt to execute this instruction, I get an error that says
> > "Access
> > > to the Path <strFileSpec> is Denied".

> > > I have checked all the privileges on the folder and the file and set
> them
> > so
> > > that "Everyone" have full access.  I can't figure out what's preventing
> > > VB.Net from deleting this file.

> > > Any ideas?

> > > Thanks,

> > > Chuck



Mon, 28 Nov 2005 20:15:30 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. SystemDB (Security files) question

2. Security Question!!!

3. pointed question on Outlook object security

4. Outlook XP Security Question

5. System.Net.NetworkCredential - Security Question

6. MS Access security question

7. security question

8. Questions to System.Security.Cryptography

9. VB.NET Security Question

10. Security Question with ODBC databases

11. vb4.0 and access 2.0 security question

12. NT and Access security question

 

 
Powered by phpBB® Forum Software