cvele
cvele

Reputation: 51

Listbox-selecting items that are read from isolatedstorage

Ok, here is a simple code, that will explain what i need to do:

IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
            StreamWriter writeFile;
            if (!store.DirectoryExists("SaveFolder"))
            {

                store.CreateDirectory("SaveFolder");



                writeFile = new StreamWriter(new IsolatedStorageFileStream("SaveFolder\\SavedFile.txt", FileMode.CreateNew, store));
            }
            else
            {

                writeFile = new StreamWriter(new IsolatedStorageFileStream("SaveFolder\\SavedFile.txt", FileMode.Append, store));
            }
            StringWriter str = new StringWriter();
            str.Write(urlHolder.Text);
            writeFile.WriteLine(str.ToString());
            writeFile.Close();

So, i have a isolatedstorage where i keep some links, that are read from some textbox(urlHolder), on the other side, i read those links and put them in listbox:

IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();



            StreamReader readFile = null;
            try
            {
                readFile = new StreamReader(new IsolatedStorageFileStream("SaveFolder\\SavedFile.txt", FileMode.Open, store));
                string fileText = readFile.ReadToEnd();

                bookmarkListBox.Items.Add(fileText);

                readFile.Close();
            }

            catch
            {
                MessageBox.Show("Need to create directory and the file first.");
            }

The thing with writing and reading is ok, but the problem is when that links are in listbox, when i want to select one of them it selects all of them...i tried everything, but no result, so, if anyone knows some solution, please write...Thanks!

Upvotes: 1

Views: 646

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 65586

You're reading the whole file as a single string and then adding it as a single item in the ListBox.

You need to add the lines/links as separate items. Try something like:

while (var item = readFile.ReadLine())
{
    bookmarkListBox.Items.Add(item);
}

Upvotes: 1

Related Questions