I am trying to add the ability to save the playlist in my media player (based on WMP), so that it can be or will be loaded automatically in the next session.
The media player itself and the playlist work flawlessly. I've tried some methods I found on the web about this but I didn't have any luck with them.
More Specifically, I want the user to be able to save the playlist with a button and then load it with another button or automatically.
The Playlist is made with Listboxes. Both the file name and file path are being logged when the user opens a file.
As you asked, I am giving below the code that I am having problems with:
For the Save button
Dim SaveFile As New SaveFileDialog SaveFile.Filter = "test playlist file |*.testfile" SaveFile.ShowDialog() Dim WriteFile As New System.IO.StreamWriter(SaveFile.FileName) For i As Integer = 0 To ListBox1.Items.Count - Val(1) WriteFile.Write(ListBox1.Items.Item(i) & ";") Next For k As Integer = 0 To ListBox2.Items.Count - Val(1) WriteFile.Write(ListBox2.Items.Item(k) & ";") Next
For the Load button
Dim OpenFile As New OpenFileDialog OpenFile.Filter = "test playlist file |*.testfile" OpenFile.ShowDialog() Dim ReadFile As New System.IO.StreamReader(OpenFile.FileName) Dim Content As String = Readfile.ReadToEnd ReadFile.Close() Dim SplittedContent() As String Dim Count As String SplittedContent = Content.Split(";") Count = SplittedContent.Count - Val(1) For i As Integer = 0 To Count ListBox1.Items.Add(SplittedContent(i)) Next For k As Integer = 0 To Count ListBox2.Items.Add(SplittedContent(k)) Next
Please note that Listbox1 holds the path of the file and Listbox2 the name of it respectively.
With this code, the file is saved successfuly, however it is empty when I open it with Notepad++.