Problem with FileStream - FileNotFoundException

  • Thread starter Thread starter Radek
  • Start date Start date
R

Radek

Hi,
I have the following problem with FileStream. In this line:

FileStream file = new FileStream(filePath, FileMode.Append);

there is an exception FileNotFoundException. But for sure path and file name
(which are both concatenated to filePath) is correct and leads to the
existing directory. User on which application is running has full permision
to the destination folder. On MSDN stands that FileMode.Append ensures that
if file exists it will be opened otherwise new file will be created.
I've cheked other constructors of the FileStream class and the same
exception is thrown. The most surprising thing is that bug does not occur in
all cases. It is possible to change destination folder and everything is ok.
Can the problem be caused by number of files in destination folder (there is
more than tousand files)?
Do you have any suggestion what should I do? Or do you know why such
exception can occur?

My environment:
I'm using ASP.NET 2.0 on IIS 6.0 (Windows 2003). Destination folder is on
the other computer in the same domain (Active Directory is in use).
 
Radek said:
Hi,
I have the following problem with FileStream. In this line:

FileStream file = new FileStream(filePath, FileMode.Append);

there is an exception FileNotFoundException. But for sure path and file name
(which are both concatenated to filePath) is correct and leads to the
existing directory. User on which application is running has full permision
to the destination folder. On MSDN stands that FileMode.Append ensures that
if file exists it will be opened otherwise new file will be created.
I've cheked other constructors of the FileStream class and the same
exception is thrown. The most surprising thing is that bug does not occur in
all cases. It is possible to change destination folder and everything is ok.
Can the problem be caused by number of files in destination folder (there is
more than tousand files)?
Do you have any suggestion what should I do? Or do you know why such
exception can occur?

My environment:
I'm using ASP.NET 2.0 on IIS 6.0 (Windows 2003). Destination folder is on
the other computer in the same domain (Active Directory is in use).

Are content of variable "filePath" like "\\jack\folder\fileapp.txt" ?
 
if you are sure the file exists, then the message means the thread doing
the open does not have read access to the file (or the directory).

to access a network share with asp.net, the pool identity should be a
domain account with access to the share. impersonation must be turned
off. if you need to impersonate the user, then windows authentication
can not be used. you must switch to basic, or kerberos (and enable
credentials forwarding on all affected servers).

-- bruce (sqlwork.com)
 
if you are sure the file exists, then the message means the thread doing
the open does not have read access to the file (or the directory).

but if I remove access rights to the directory AccessDeniedException is
thrown. Are you sure that read access can cause such problem that
FileNotFoundException is thrown in some cases?
to access a network share with asp.net, the pool identity should be a
domain account with access to the share. impersonation must be turned off.
if you need to impersonate the user, then windows authentication can not
be used. you must switch to basic, or kerberos (and enable credentials
forwarding on all affected servers).

indeed I have to impersonate user and to use windows authentication as well.
I don't suppose that this is the reason why exception is thrown, because if
I change the path to another folder it works. Account on which
impersonalization is made is domain account
 
Are content of variable "filePath" like "\\jack\folder\fileapp.txt" ?

yes, something like this
 
Back
Top