Windows Develop Bookmark and Share   
 index > Windows Forms General > Access denied attempting to delete file
 

Access denied attempting to delete file

i'm trying to delete some files in a Windows application but I'm getting an Access denied error. The path is a share, and I've setthe share permissionsfor Everyone to Full Access. I've also set thefile permissions on all files and the folder they're infor Everyone to Full Access.I can manually delete the files in question, naturally.

A couple of questions: What's the default identity for a Windows application? Is it the user who launched the application? Anyone have any ideas?

Here's the code:

Dim sFiles() As String = x.GetFiles("\\myserver\myshare\", "*.txt")

Dim FI As FileInfo

For i As Integer = 0 To sFiles.GetUpperBound(0)

FI = New FileInfo(sFiles(i))

If DateDiff(DateInterval.Day, FI.LastWriteTime, Now) >= iDaysOld Then

File.Delete(sFiles(i)) 'kicks out Access Denied error with the path above, with c:\temp\ it works fine

End If

Next

Thanks Alex

AlexB-007  Wednesday, June 25, 2008 7:06 PM
Have you examined the value of --> sFile(i) <--- at runtime? What is it? The application should be running under the username of whomever, or whatever, launched the application.

Rudedog
Rudedog2  Wednesday, June 25, 2008 7:58 PM

Hi Alex,

I performed a test based on your description but didn't reproduce the problem on my side.

In my test, I create a sharing folder named "update folder" in the D:\ and set the Permission Level for Everyone to "Co-owner". Then I createa txt file named txt1.txt in the "update folder".

Create aWinForm application project and add a Button on the form. In the Button's Click event handler,add the following lines of code to delete the txt1.txt file:

private void button1_Click(object sender, EventArgs e)
{
FileInfo fi = new FileInfo(@"\\myservername\update folder\txt1.txt");
fi.Delete();
}

Build and run the application. Click the Button on the form and the txt1.txt file in the "update folder" is deleted.

Hope this helps.

Linda

Linda Liu  Friday, June 27, 2008 9:00 AM
Hi,
Try setting the IsReadOnly property on the FileInfo to 'false', then delete it using fi.Delete() method.

Lior.
Lior Salem  Friday, June 27, 2008 12:34 PM

You can use google to search for other answers

Custom Search

More Threads

• text based games for beginers
• Drawing an object on a form load event
• Hardware Information in VB.net 2005
• Problems with webbrowser & HTML Tables in VB.NET
• Align data in drop down list
• DialogForm closing problem????
• disabling close button on form's title bar
• RichTextBox as a drag and drop source for string (text) data
• Scrollbar problem
• Listview scroll down with down key, last items invisible