2019-03-17 16:07:08

Hello!
The task I want to do is simple, save the checked items to a text file. However, the file that the app creates i empty. What's wrong with my code? Here is the faulty snipped
foreach (object ItemChecked in GameList.CheckedItems)
            {
                CheckedItemID = ItemChecked.ToString();
            }SW.WriteLine(CheckedItemID);
        }
        }

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2019-03-17 16:09:32

This might be a stupid question, as I have barely any knowledge in this field but, are you closing the file once you are done?

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2019-03-17 16:15:35

As far as i am concerned it is not needed

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2019-03-17 18:18:57

The StreamWriter buffers your writes in memory, and only once a certain amount of data has been written does it actually send it out to the HDD/SSD.
You can force it to send it by calling sw.Flush(), or sw.Close().
Also, in your code snippet the SW.WriteLine(CheckedItemID); has a right curly brace in front of it which puts it outside the for loop.
This means that even if you were seeing what it wrote, it would only write the last checked item, not all of them.

~ Ian Reed
Visit BlindGamers.com to rate blind accessible games and see how others have rated them.
Try my free JGT addon, the easy way to play Japanese games in English.
Or try the free games I've created.

2019-03-17 18:26:57

Thanks Ian for your help. I will apply your instructions smile

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2019-03-17 22:26:53 (edited by kianoosh 2019-03-17 22:27:15)

to be honest I never used filestream for my IO operations. I always used system.io, File object(if I can remember correctly)

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2019-03-19 18:40:35

As far as I can tell, the call to write is occurring outside of the foreach loop, so it isn't actually writing each item to the file.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2019-03-19 19:12:37

Thank you all for your help. Now I have a different problem. Can I strip a file from blank lines somehow? I am asking it here, cause I don't want to spam the forum

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com