c# - Save ListBox_SelectedItem to file.txt -
Hi all, I want to save in file.txt chronology of the song played by my music player I try this code snippet But does not work:
StreamWriter sw = new streamer (@ "c: \ Media PlayList \ List.txt"); Private Zero ListBoxie 1 converted integrated index (object sender, eventArgse E) {wmp.URL = Convert.trustring (list box 1. selected input); Forward (object o.elected items in the list box) {sw.WriteLine (DateTime.Now + "-" + o.ToString ()); }} How do I archive songs:
Private list & lt; String & gt; GetFolder (string folder) {string filena; DirectoryInfo dir = new DirectoryInfo (folder); FileInfo [] Files = DIRGateFile ("*. Mp3", SearchOption.AllDirectories); & Lt; String & gt; Str = new list & lt; String & gt; (); Forward (files in fileinfo file) {str.Add (file.FullName); }} Private Zero Form 2_load (Object Sender, EventAgds E) {List & lt; String & gt; Uno = GetFolder (@ "D: \\ Music \\"); ListBox1.DataSource = uno; ListBox1.DisplayMember = "uno"; } Every time I like to sing a music player, a file named "list.txt" will be updated by the listbox. Selected ITem but I can not update "List.txt" with my code. Where is I wrong? Thank you for your kind attention.
Good relationship
EDIT: I hope that my code snippet has been updated, it will be clear.
using the system; Using System.Collections.Generic; Using System.IO; Using System.Windows.Forms; Name Location WindowsApplication1 {Public Partial Class} Form 1: Form {Public Form 1 () {Initial Group (); ListBox1.DataSource = GetFolder ("D: \\ Music \\"); } Private Static List & lt; String & gt; GetFolder (string folder) {list & lt; String & gt; File list = new list & lt; String & gt; (); Foreign exchange (new directoryInfos file file in folder (.file). Gatefile ("* .mp3", searchoptions, all directories)) file list. Add (File. Full Name); Return file list; } Private Zero catalogBoxie 1 sealed integrated index (object sender, eventarges e) {stream w = new streamer ("c: \\ media playlist \\ list .ttek", true); Wmp.URL = Convert. Toasting (listBox1.SelectedItem); Foreign objects (objects selected in the list box.) Sw.WriteLine (Datetime. Now + "-" + O); Sw.Close (); }}} The above code will work for you. Note:
- If you want to add to the file, then you must be correct as the second argument to create the Stream Werner.
- After writing your data in the file, you should explicitly close the stream, or your file will be empty.
- After closing the file you can not write it now if you want to open it again.
Comments
Post a Comment