473,835 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UnauthorizedAcc essException

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 {
FileIOPermissio n _fioPermit = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , _filePath);
_fioPermit.Asse rt();

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

Nov 17 '05 #1
4 4214
trying using the unc path IE \\Server\drive_ c\
"ASP Yaboh" <AS******@discu ssions.microsof t.com> wrote in message
news:CE******** *************** ***********@mic rosoft.com...
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 {
FileIOPermissio n _fioPermit = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , _filePath);
_fioPermit.Asse rt();

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

Nov 17 '05 #2
Mel, I just finished trying that - same problem. Thank you though. T

"Mel Weaver" wrote:
trying using the unc path IE \\Server\drive_ c\
"ASP Yaboh" <AS******@discu ssions.microsof t.com> wrote in message
news:CE******** *************** ***********@mic rosoft.com...
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 {
FileIOPermissio n _fioPermit = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , _filePath);
_fioPermit.Asse rt();

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


Nov 17 '05 #3

"ASP Yaboh" <AS******@discu ssions.microsof t.com> wrote in message
news:CE******** *************** ***********@mic rosoft.com...
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 {
FileIOPermissio n _fioPermit = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , _filePath);
_fioPermit.Asse rt();

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


"UnauthorizedAc cessException" is thrown when the "user" running the code has
no "access permissions", note that FileIOPermissio n have nothing to do with
this, FileIOPermissio n 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,especi ally when the client is a long
running process (service).

Willy.


Nov 17 '05 #4
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 [MVP]" wrote:

"ASP Yaboh" <AS******@discu ssions.microsof t.com> wrote in message
news:CE******** *************** ***********@mic rosoft.com...
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 {
FileIOPermissio n _fioPermit = new
FileIOPermissio n(FileIOPermiss ionAccess.Write , _filePath);
_fioPermit.Asse rt();

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


"UnauthorizedAc cessException" is thrown when the "user" running the code has
no "access permissions", note that FileIOPermissio n have nothing to do with
this, FileIOPermissio n 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,especi ally when the client is a long
running process (service).

Willy.


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3144
by: Doug Taylor | last post by:
Hi, I originally posted this in dotnet.security, but have moved it here by request: Hi, I am trying to programmatically add a user with read permissions to the DACL of a registry key. All appears to go well until I try to
1
1852
by: Hal 9000 | last post by:
In c# we have a function that creates a virtual directory in IIS 6.0 using DirectoryServices API. The code looks like this: // log in to IIS DirectoryEntry rootDir = new DirectoryEntry("IIS://localhost/W3SVC/1/Root",ADMIN_USR,ADMIN_PSWD,AuthenticationTypes.Secure); // create a child virtual directory DirectoryEntry virtualDir = rootDir.Children.Add(name, rootDir.SchemaClassName); // set the virtual directory's physical path
12
8024
by: Lucas Tam | last post by:
I have a very simple loop: If (Directory.Exists(tempDirectory)) Then Try Dim Files() As String = Directory.GetFiles(tempDirectory) 'Clear out directory For Each Filename As String In Files File.Delete(Filename) Next Catch ex As Exception
0
2335
by: nime | last post by:
I've got a problem. I cannot debug my app. which one contains WebBrowser control. I found a resolution but it's for an ASP related problem. I couldn't find a correct "user" to give permisson then I've added Everyone and refreshed policies (gpupdate /force), restarted VB IDE but still got the problem. What is the "worker process" for VB IDE? CODE:
8
6321
by: imukai | last post by:
I have a forms-based authentication application on our intranet - ASP.NET 3.5 (C#). For security purposes there is one specific .aspx file that we have enabled Integrated Windows Authentication turned on. Administrators in another group control access to this .aspx file via the file system. They have specifically set DENY access on this file to a few groups of employees. If one of those employees somehow manages to bring up that .aspx,...
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9653
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10562
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6968
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.