Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SecurityException and DIR function...

Status
Not open for further replies.

mmorancbt

IS-IT--Management
Nov 11, 2002
367
US
I have a simple (what I believe is a simple) page that has the following on page load..

Code:
Sub Page_Load(Sender as Object, e as EventArgs)
        Dim MyPath, MyName As String
        MyPath = Server.MapPath("Upload")
        MyName = Dir(MyPath, vbDirectory)
End Sub

This code used to include code to create a directory of it didn't exist - for uploading a file via .NET.

The upload code works fine but I am getting a securityexception error on the End Sub line whenever I include the DIR function.

Currently, I am not really using it - I stripped it out and my later code - for uploading to the Upload folder works both locally and with my hosted solution.

However, I am still curious why I am getting the error. If I am able to upload a file from my form - using .NET, why can I not use the DIR function to read from the same folder. I will need to build a list of files from this folder soon.

Thanks.

Matthew Moran (career blog and podcast below)
Career Advice with Attitude for the IT Pro
 
Try using the framework methods System.IO.Directory.Exists() and System.IO.Directory.CreateDirectory() and see if the same applies. If it does, the user that your application is running under doesn't have the necessary permissions.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Using my code above - where I have the proper folder identified, how would I use the System.IO,Directory.Exist() function?

I know I am being lazy and will look it up, but I am on a different problem right now - so easy/lazy is my first resort.

Thanks.

Matthew Moran (career blog and podcast below)
Career Advice with Attitude for the IT Pro
 
Okay, laziness abated - work completed...

It worked fine, so we are using the:

System.IO,Directory.Exist()

Now I am writing it to use the:
System.IO.Directory.GetFiles() method - because it allows me to iterate through files by mask...

Thanks.

Matthew Moran (career blog and podcast below)
Career Advice with Attitude for the IT Pro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top