Reputation: 483
I was trying to make a list with stuff people can put in there likea shopping list but my program cannot access the C:\ drive so i decidedto put it into the resourcefolder but that didnt work someone has any idea how to let is work/??
my code:
Private Sub ThirteenButton14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThirteenButton14.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
Dim i As Integer
w = New IO.StreamWriter(My.Resources.FavoriteList)
For i = 0 To ListBox1.Items.Count - 1
w.WriteLine(ListBox1.Items.Item(i))
Next
w.Close()
ListBox1.Items.Clear()
R = New IO.StreamReader(My.Resources.FavoriteList)
While (R.Peek() > -1)
ListBox1.Items.Add(R.ReadLine)
End While
R.Close()
End Sub
Private Sub ThirteenButton13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThirteenButton13.Click
ListBox1.Items.Add(ThirteenTextBox6.Text + " | " + ThirteenTextBox7.Text)
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
Dim i As Integer
w = New IO.StreamWriter(My.Resources.FavoriteList)
For i = 0 To ListBox1.Items.Count - 1
w.WriteLine(ListBox1.Items.Item(i))
Next
w.Close()
ListBox1.Items.Clear()
R = New IO.StreamReader(My.Resources.FavoriteList)
While (R.Peek() > -1)
ListBox1.Items.Add(R.ReadLine)
End While
R.Close()
End Sub
this didnt work for me. any help is apreciated y=thanks
Upvotes: 0
Views: 4690
Reputation: 54477
An application doesn't have a "resource folder". Your project has such a folder because that's where the source items are stored but the whole point of resources is that they are data compiled into the EXE itself. As such, they are read-only. If you want a common location that all users can safely write to then use the public documents folder.
As for your code, if you add a file to your resources then it's the contents of that file that gets compiled into the EXE and returned via My.Resources. There is no file at run time so there is no file path at run time, so your attempts to create a StreamReader and StreamWriter are bound to fail. I assume that you have added a text file as a resource. In that case, My.Resources.FavoriteList is going to return the contents of that file as a String. You can use that data but you cannot modify it and save the changes back to the resource because that resource is part of your EXE.
Upvotes: 1