UnauthorizedAccessException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ASP Yaboh

    UnauthorizedAccessException

    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.
    .. . .

  • Mel Weaver

    #2
    Re: UnauthorizedAcc essException

    trying using the unc path IE \\Server\drive_ c\


    "ASP Yaboh" <ASPYaboh@discu ssions.microsof t.com> wrote in message
    news:CE0E7A98-1E80-44BC-8D4A-3741E3D91453@mi crosoft.com...[color=blue]
    >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.
    > . . .
    >[/color]


    Comment

    • ASP Yaboh

      #3
      Re: UnauthorizedAcc essException

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

      "Mel Weaver" wrote:
      [color=blue]
      > trying using the unc path IE \\Server\drive_ c\
      >
      >
      > "ASP Yaboh" <ASPYaboh@discu ssions.microsof t.com> wrote in message
      > news:CE0E7A98-1E80-44BC-8D4A-3741E3D91453@mi crosoft.com...[color=green]
      > >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.
      > > . . .
      > >[/color]
      >
      >
      >[/color]

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: UnauthorizedAcc essException


        "ASP Yaboh" <ASPYaboh@discu ssions.microsof t.com> wrote in message
        news:CE0E7A98-1E80-44BC-8D4A-3741E3D91453@mi crosoft.com...[color=blue]
        >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.
        > . . .
        >[/color]

        "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.




        Comment

        • ASP Yaboh

          #5
          Re: UnauthorizedAcc essException

          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:
          [color=blue]
          >
          > "ASP Yaboh" <ASPYaboh@discu ssions.microsof t.com> wrote in message
          > news:CE0E7A98-1E80-44BC-8D4A-3741E3D91453@mi crosoft.com...[color=green]
          > >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.
          > > . . .
          > >[/color]
          >
          > "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.
          >
          >
          >
          >
          >[/color]

          Comment

          Working...