deleting file - access denied

  • Thread starter Thread starter MA
  • Start date Start date
M

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
 
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,
 
Check the security setting of the folder. It should have "Modify"
permissions to everyone user.

Dalvir Singh
 
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
 
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.
 
Back
Top