删除文件 - 访问被拒绝 [英] deleting file - access denied

查看:85
本文介绍了删除文件 - 访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我创建了一个web服务,检查传入和传出文件的文件夹。如果我的收件箱(传入文件)中存在
a文件,我会读取它并想删除它。

看起来像这样:


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作品除了fname.Delete();

我得到了拒绝访问权限。如果我在资源管理器中查看

属性,该文件不是只读的。


如何解决此问题?


/ Marre

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

推荐答案




很可能另一个进程正在访问该文件。它甚至可以是你的b
相同的过程!

如果你使用FileSystemWatcher,它可能会为

更改生成多个事件。取决于你正在使用什么事件。


转到sysinternals.com并下载他们拥有的文件监控工具,你好b / b $ b将知道什么进程正在使用什么文件

欢呼,

-

Ignacio Machin,

ignacio.machin at dot.state.fl。我们

佛罗里达州交通局


" MA" <是ne ** @ supremelink.se>在留言中写道

新闻:2q ************ @ uni-berlin.de ...
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" <ne**@supremelink.se> wrote in message
news:2q************@uni-berlin.de...
大家好!

我创建了一个web服务,检查传入和传出文件的文件夹。
如果我的收件箱中存在一个文件(传入文件),我会读取它并想删除它。
它看起来像这样:

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

字符串行= myStream.ReadLine();
while(line!= null)
{
content + = line;
line = myStream.ReadLine();
}
myStream.Close();

fname.Delete();
}

它的工作原理除了fname.Delete();
我得到了拒绝访问权限。如果我在资源管理器中查看
属性,该文件不是只读的。

如何解决这个问题?

/ Marre
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



Thanx快速回答!


我现在就检查这个!


/ Marre

Ignacio Machin(.NET / C#MVP)" < ignacio.machin AT dot.state.fl.us>在消息新闻中写了

:Oi ************** @ TK2MSFTNGP12.phx.gbl ...
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:Oi**************@TK2MSFTNGP12.phx.gbl...

很可能另一个进程正在访问该文件。它甚至可以是你的相同过程!
如果你使用FileSystemWatcher,它可能会为
更改生成多个事件。取决于您正在使用的事件。

转到sysinternals.com并下载他们拥有的文件监控工具,
您将知道什么进程正在使用什么文件
欢呼,

-
Ignacio Machin,
ignacio.machin at dot.state.fl.us
佛罗里达州交通局
MA <是ne ** @ supremelink.se>在消息中写道
新闻:2q ************ @ uni-berlin.de ...
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" <ne**@supremelink.se> wrote in message
news:2q************@uni-berlin.de...
大家好!

我创建了一个web服务,检查传入和传出文件的文件夹。
Hi all!

I created a webservice that check folder for incoming and outgoing files.


如果

我的收件箱中存在一个文件(传入文件)我读了它并想要删除
它。
它看起来像这样:

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

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

fname.Delete( );
}

它的工作原理除了fname.Delete();
我得到了拒绝访问权限。如果我在资源管理器中查看
属性,该文件不是只读的。

如何解决这个问题?

/ Marre
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







很可能另一个进程正在访问该文件。它甚至可以是你的b
相同的过程!

如果你使用FileSystemWatcher,它可能会为

更改生成多个事件。取决于你正在使用什么事件。


转到sysinternals.com并下载他们拥有的文件监控工具,你好b / b $ b将知道什么进程正在使用什么文件

欢呼,

-

Ignacio Machin,

ignacio.machin at dot.state.fl。我们

佛罗里达州交通局


" MA" <是ne ** @ supremelink.se>在留言中写道

新闻:2q ************ @ uni-berlin.de ...
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" <ne**@supremelink.se> wrote in message
news:2q************@uni-berlin.de...
大家好!

我创建了一个web服务,检查传入和传出文件的文件夹。
如果我的收件箱中存在一个文件(传入文件),我会读取它并想删除它。
它看起来像这样:

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

字符串行= myStream.ReadLine();
while(line!= null)
{
content + = line;
line = myStream.ReadLine();
}
myStream.Close();

fname.Delete();
}

它的工作原理除了fname.Delete();
我得到了拒绝访问权限。如果我在资源管理器中查看
属性,该文件不是只读的。

如何解决这个问题?

/ Marre
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



这篇关于删除文件 - 访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆