none
have problem with this block of code RRS feed

  • Question

  • Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
    
    
    
            REM save listview1 text
            Dim writer10 As TextWriter = New StreamWriter("C:\\ItemDataView6.txt")
            Dim row10 As New StringBuilder(), i10 As Integer
    
            Dim itm10 As ListViewItem
    
            For Each itm10 In ListView1.Items
    
                For i = 0 To 4
    
                    row10.Append(itm10.SubItems(i10).Text & vbTab)
    
                Next
    
                writer10.WriteLine(row10.ToString())
    
                row10.Remove(0, row10.Length)
    
            Next
    
            writer10.Close()
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
            Shipping3.Show()
            Me.Hide()
        End Sub
    ok this is giving me

    An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

    Additional information: Access to the path 'C:\ItemDataView6.txt' is denied.

    and I am the admin for my system


    Saturday, March 2, 2019 1:10 PM

Answers

  • Use the following path instead

    Dim fileName As String = IO.Path.Combine(
        My.Computer.FileSystem.SpecialDirectories.MyDocuments, "ItemDataView6.txt")

    So on my machine this would be C:\Users\Karens\Documents


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Dan Sprouse Saturday, March 2, 2019 6:29 PM
    Saturday, March 2, 2019 1:32 PM
    Moderator

All replies

  • Hi

    Try using a 'User' location for the file - such as Documents (or any sub folder within).

    If your project is destined for other computers, then you could save a lot of headaches by sticking to 'safe' locations.


    Regards Les, Livingston, Scotland

    Saturday, March 2, 2019 1:23 PM
  • Use the following path instead

    Dim fileName As String = IO.Path.Combine(
        My.Computer.FileSystem.SpecialDirectories.MyDocuments, "ItemDataView6.txt")

    So on my machine this would be C:\Users\Karens\Documents


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Dan Sprouse Saturday, March 2, 2019 6:29 PM
    Saturday, March 2, 2019 1:32 PM
    Moderator