deleting file - access denied
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.

Post a new message to this list...

MA
Hi all!

I created a webservice that check folder for incoming and outgoing files. If
a file exists in my inbox (incoming file) I read it and want to delete it.
It looks like this:

foreach(FileInfo fname in folder.GetFiles())
{
if(fname.Exists)
{
myStream = new StreamReader(fname.FullName,Encoding.Default);

string line = myStream.ReadLine();
while(line != null)
{
content += line;
line = myStream.ReadLine();
}
myStream.Close();

fname.Delete();
}

It works except for fname.Delete();
I get an access denied on this. The file is not read-only if I check
properties in Explorer.

How can I fix this?

/Marre

Reply to this message...
 
    
Ignacio Machin \( .NET/ C# MVP \)
Hi,

Most probably another process is accesing the file. It can even be your
same process !
IF you use a FileSystemWatcher it may generate more than one event for a
"change" depending of what events you are using.

Go to sysinternals.com and download the file monitoring tool they have, you
will know what process is using what file

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"MA" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
MA
Thanx for the quick answer!

I will check this right now!

/Marre
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Dalvir Singh
Check the security setting of the folder. It should have "Modify"
permissions to everyone user.

Dalvir Singh

"MA" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
MA
Well, my knowledge level of these permission-things are really low.

Where can I set this permission on my folder? When I rightclick on my folder
and choose properties, I can´t set any permissions . Is there another way?

/Marre
"Dalvir Singh" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Dalvir Singh
Right click on the folder and choose properties. Go to "Security" Tab (4th
one). In the name list search for "evryone".
If you can't see everyone user in list, then click add button on right top.
In the users list appeared, search for everyone and click "Add" and then
"OK."
Now you can see everyone user in the security tab of properties window.
Click on "everyone" user" and see permissions box below it. Under the allow,
verify that Modify is selected. If no, then select it.

Hope that helps.

--
Dalvir Singh

"MA" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
MA
Hmm....I do not have this Tab....and I´m logged in as administrator......

/Marre
"Dalvir Singh" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.IO.FileInfo
System.IO.FileSystemWatcher
System.IO.StreamReader
System.Text.Encoding




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com