UnauthorizedAccessException

G

Guest

I have app that writes text files to any location of the users choosing in
the network. It has been working for 18months. An exception has begun
occurring where a folder on a network share is denying access to the
File.CreateText(_filename) method. The user has write access. They can create
a text file through explorer no problem.

I am not a member of the group that has write access. As a test, I logged
into the network as a Domain Admin and ran the app. No problem writing the
text file.

The server is Win2003 sp1. The code is listed below. Any help would be
appreciated.
Thank you. tberry

.. . .
try {
FileIOPermission _fioPermit = new
FileIOPermission(FileIOPermissionAccess.Write, _filePath);
_fioPermit.Assert();

StreamWriter sw = File.CreateText(filename);// Exception occurs here.
for (i = 0; i < count; i++) {
sw.WriteLine((string)dataList);
}// for
sw.Flush();
sw.Close();
sw = null;
return true;
} catch(UnauthorizedAccessException uae) {
// User does not have access rights to file, folder or drive.
.. . .
 
G

Guest

Mel, I just finished trying that - same problem. Thank you though. T

Mel Weaver said:
trying using the unc path IE \\Server\drive_c\


ASP Yaboh said:
I have app that writes text files to any location of the users choosing in
the network. It has been working for 18months. An exception has begun
occurring where a folder on a network share is denying access to the
File.CreateText(_filename) method. The user has write access. They can
create
a text file through explorer no problem.

I am not a member of the group that has write access. As a test, I logged
into the network as a Domain Admin and ran the app. No problem writing the
text file.

The server is Win2003 sp1. The code is listed below. Any help would be
appreciated.
Thank you. tberry

. . .
try {
FileIOPermission _fioPermit = new
FileIOPermission(FileIOPermissionAccess.Write, _filePath);
_fioPermit.Assert();

StreamWriter sw = File.CreateText(filename);// Exception occurs here.
for (i = 0; i < count; i++) {
sw.WriteLine((string)dataList);
}// for
sw.Flush();
sw.Close();
sw = null;
return true;
} catch(UnauthorizedAccessException uae) {
// User does not have access rights to file, folder or drive.
. . .

 
W

Willy Denoyette [MVP]

ASP Yaboh said:
I have app that writes text files to any location of the users choosing in
the network. It has been working for 18months. An exception has begun
occurring where a folder on a network share is denying access to the
File.CreateText(_filename) method. The user has write access. They can
create
a text file through explorer no problem.

I am not a member of the group that has write access. As a test, I logged
into the network as a Domain Admin and ran the app. No problem writing the
text file.

The server is Win2003 sp1. The code is listed below. Any help would be
appreciated.
Thank you. tberry

. . .
try {
FileIOPermission _fioPermit = new
FileIOPermission(FileIOPermissionAccess.Write, _filePath);
_fioPermit.Assert();

StreamWriter sw = File.CreateText(filename);// Exception occurs here.
for (i = 0; i < count; i++) {
sw.WriteLine((string)dataList);
}// for
sw.Flush();
sw.Close();
sw = null;
return true;
} catch(UnauthorizedAccessException uae) {
// User does not have access rights to file, folder or drive.
. . .


"UnauthorizedAccessException" is thrown when the "user" running the code has
no "access permissions", note that FileIOPermission have nothing to do with
this, FileIOPermission is a Code Access permission.
All you can do is turn on auditing on the File server and check the identity
of the "user account" accessing the Fileshare when it fails.
Also make sure to use UNC paths as filename, using Drive mapping is in
general the cause of such failures,especially when the client is a long
running process (service).

Willy.
 
G

Guest

Willy,

I tried using the UNC in the path without success. I will try your
suggestion about turning auditing.

Thank you for your time,
Tom

Willy Denoyette said:
ASP Yaboh said:
I have app that writes text files to any location of the users choosing in
the network. It has been working for 18months. An exception has begun
occurring where a folder on a network share is denying access to the
File.CreateText(_filename) method. The user has write access. They can
create
a text file through explorer no problem.

I am not a member of the group that has write access. As a test, I logged
into the network as a Domain Admin and ran the app. No problem writing the
text file.

The server is Win2003 sp1. The code is listed below. Any help would be
appreciated.
Thank you. tberry

. . .
try {
FileIOPermission _fioPermit = new
FileIOPermission(FileIOPermissionAccess.Write, _filePath);
_fioPermit.Assert();

StreamWriter sw = File.CreateText(filename);// Exception occurs here.
for (i = 0; i < count; i++) {
sw.WriteLine((string)dataList);
}// for
sw.Flush();
sw.Close();
sw = null;
return true;
} catch(UnauthorizedAccessException uae) {
// User does not have access rights to file, folder or drive.
. . .


"UnauthorizedAccessException" is thrown when the "user" running the code has
no "access permissions", note that FileIOPermission have nothing to do with
this, FileIOPermission is a Code Access permission.
All you can do is turn on auditing on the File server and check the identity
of the "user account" accessing the Fileshare when it fails.
Also make sure to use UNC paths as filename, using Drive mapping is in
general the cause of such failures,especially when the client is a long
running process (service).

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top