Security Exception was unhandled RRS feed

  • Question

  • Hello,

    I'm debugging a VB.NET code that is supposed to create a logfile for a conversion program if any errors are found when converting the data and transferring it to a MS SQL Server database.

    I keep getting an error stating "SecurityException was unhandled". I was told that the reason why this occurred was because of the permission access in windows 7 as it does not allow programs to write to the windows root directory (C:).

    So I implemented a code to get the file path of the user's appdata directory and store the program logs in that location but the same error about the security exception keeps coming up.

    Below is the code currently being debugged:

    Sub CreateLog2()
            Dim log As Scripting.FileSystemObject
            Dim logfile As Scripting.TextStream
            Dim logf As String
            Dim appData As String = GetFolderPath(SpecialFolder.ApplicationData) 'Gets folder path of appdata as it varies on different machine
            logf = appData
            log = New Scripting.FileSystemObject
            logfile = log.CreateTextFile(logf, True) 'At this line it gives the error
        End Sub

    Thank you for your time and your response :)

    Tuesday, July 17, 2012 3:58 PM


  • It still might be that you don't have permissions to create text file to the AppData folder. You should verify the required permissions first.
    • Proposed as answer by Mike Feng Wednesday, July 18, 2012 9:54 AM
    • Marked as answer by Mike Feng Friday, July 27, 2012 9:41 AM
    Tuesday, July 17, 2012 5:54 PM