The Program runs a query on a SQL Database, then it takes the gathered information and outputs it into an excel document and saves it to a specified location.
Problem:
I currently have a check in the Form1_Load that checks to make sure the Program is not being run from a network location. It does this by trying to create Folders on a network drive. If the program is stored on the network drive and it tries to create the folders it throws a System.Security.SecurityException. Currently the way it is set up after it tries to create the folders and throws an exception, the exception is caught and a MsgBox is displayed notifying the user that the program can’t be run from a network location. The Problem lies in the fact that after it displays that box and the user clicks ok it displays a Microsoft .Net Framework Dialog Box. The Box says “Application attempted to perform an operation not allowed by the security policy.” The box gives the options of Details, Continue and Quit. If you click Quit…it quits, like it should. If you click Continue it opens the Program anyways. In the Catch it says to display the MsgBox and exit the program.
Question:
How can I make it not Display the dialog box? Or how can I make it quit before it displays the dialog box? Also I probably did this Try, Catch and Throw Incorrectly, so how do I correctly write this?
Expand|Select|Wrap|Line Numbers
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- ' Check to make sure Program is being run locally
- Try
- ' Create file directory
- createDirectories()
- Catch ex As System.Security.SecurityException
- MsgBox("You can not open this Program from" & (vbCr) & "A network Location.", 0 + 48, "Portal Error")
- End
- End Try
- ' More Code after this but it is unnecessary to this problem
- End Sub
- Private Sub createDirectories()
- Dim i As Integer
- For i = 0 To 2
- Try
- If i = 0 Then
- MkDir("U:\Portal\")
- End If
- If i = 1 Then
- MkDir("U:\Portal\Aesop\")
- End If
- If i = 2 Then
- MkDir("U:\Portal\Reports\")
- End If
- Catch ex As Exception
- Exit Try
- End Try
- Next
- End Sub
Thank you for any help you have to offer me. If you need any more explanation to help or more code just let me know.
This is not a School Project, I am creating this program for the company I work for and I am trying to fine tune the program before I release it.