Results 1 to 7 of 7

Thread: File access denied, SecurityException

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    9

    Question File access denied, SecurityException

    Hi all,

    I'm writing a program to input a text file, manipulate the text file and output to another directory. Both the input and output files are on a mapped network drive on a server.

    My problem is, when I execute the program from a local drive, it works fine, but when I copy the programs to the same server, and execute the programs from there, it throws a securityexception and tells me to store application data in an isolated storage and blah blah.

    Thanks a lot in advance!

    Here's the code,


    VB Code:
    1. Imports System.IO
    2. Public Class Form1
    3.     Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
    4.         Dim mySR As System.IO.StreamReader
    5.         Dim mySW As System.IO.StreamWriter
    6.         Dim intX As Integer, lngRcdCounter As Long
    7.         Dim myLine() As String
    8.         Dim strX As String
    9.         Dim strSep As String = Chr(34) & "," & Chr(34)
    10.  
    11. [B]        mySR = New StreamReader("x:\input\test.csv")
    12.         mySW = New StreamWriter("x:\output\test.txt")[/B] '<----(Here's where the exception is thrown)
    13.  
    14.         Do Until mySR.EndOfStream = True
    15.             myLine = mySR.ReadLine.Split(strSep)
    16.             For intX = myLine.GetLowerBound(0) To myLine.GetUpperBound(0)
    17.                 strX = myLine(intX).Trim.ToString & Chr(34)
    18.                 mySW.Write(strX)
    19.             Next
    20.             mySW.WriteLine()
    21.             lngRcdCounter += 1
    22.         Loop
    23.         mySW.Flush()
    24.         mySW.Close()
    25.         MsgBox("Done. " & lngRcdCounter & " records processed")
    26.  
    27.     End Sub
    28. End Class

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: File access denied, SecurityException

    One thing you might want to try is using the full name of the server instead of the mapped name of the drive. The letter that it's mapped to can change depending on the computer it's running on. That may be causing the problem.

    Also, check the priviledges for the user in the output folder. It may be that it's read-only access. If that's the case, that would deffinitely cause the problem.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    9

    Re: File access denied, SecurityException

    Thanks Halo!

    Tried the full path with server name, but still got the same result. Reason I'm using mapped drive is I don't wanna change the code and recompile every time the input file's location gets changed.

    Actually, I made a mistake in my original post. The exception is thrown at the atempt to read the file, not write.

    What boggs my mind is that it works fine when the source code is copied to the local hard drive, and it doesn't when it is executed from a mapped drive. How bizzard is that? I guess this is very useful when it comes to preventing malicious code accessing the network?

    Anyhow...Thanks a lot for your help! I will keep looking

  4. #4
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: File access denied, SecurityException

    Microsoft stopped caring about developers opinions around the time the melissa virus spread

    Now they're all about securing everything and letting us fend for our salary...

    Did you check the priviledges of the user reading the file? It could be strict and not let any anonymous viewing.

    Edit: Just for clarification, I was being funny about the melissa thing, that's not the reason. I need a key on my keyboard to denote sarcasm.
    Last edited by sevenhalo; Feb 15th, 2006 at 09:27 PM.

  5. #5
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: File access denied, SecurityException

    If you use a mapped drive, it can be replaced with the server's name. It'll work exactly the same. They only use mapped drives to spare the phone tech's conversation about the difference between a forward slash and a backslash

  6. #6
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: File access denied, SecurityException

    Again, sarcasm.

    But in practice, it really feels true.

    All programmers are comedians, only a small percentage is funny. I just have a problem realizing im in that nonsmall percentage.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    9

    Talking Re: File access denied, SecurityException

    Hmmmm...tried allowing the Anonymous Login, but still wouldn't work.

    ...

    Guess I will have to spend some time in MSDN...

    Thanks Halo...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width