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 :confused: blah.
Thanks a lot in advance!
Here's the code,
VB Code:
Imports System.IO
Public Class Form1
Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
Dim mySR As System.IO.StreamReader
Dim mySW As System.IO.StreamWriter
Dim intX As Integer, lngRcdCounter As Long
Dim myLine() As String
Dim strX As String
Dim strSep As String = Chr(34) & "," & Chr(34)
[B] mySR = New StreamReader("x:\input\test.csv")
mySW = New StreamWriter("x:\output\test.txt")[/B] '<----(Here's where the exception is thrown)
Do Until mySR.EndOfStream = True
myLine = mySR.ReadLine.Split(strSep)
For intX = myLine.GetLowerBound(0) To myLine.GetUpperBound(0)
strX = myLine(intX).Trim.ToString & Chr(34)
mySW.Write(strX)
Next
mySW.WriteLine()
lngRcdCounter += 1
Loop
mySW.Flush()
mySW.Close()
MsgBox("Done. " & lngRcdCounter & " records processed")
End Sub
End Class
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.
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:)
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.
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 :)
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.
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...