Forum   Search   Register   Log in SUPERJER FORUM
 

IO Exception

Pages: [1]
Programming Help
sprinkles

Chrome Whore
2009 Sep 6 • 2431
10 ₧
Okay, so I am making a web browser.
I have a StreamWriter that writes the current url to a file. I also I have a StreamReader that (on form load) reads the file and populates my combobox with the urls. The problem is if I put the StreamWriter in the go button click method it will close and I will only write 1 line (if there are multiple urls it only writes the last one -well actually it writes all the urls the problem is it writes over the previous url). If I put the StreamWriter in the declarations I get a system IO Exception, because my StreamReader already has access the the file (the StreamWriter successfully writes multiple urls if I disable the StreamReader). So I need to find either a place for the StreamReader or StreamWriter...

Wait....

Fuck yes! My first use of an array that worked!

C# code
//Way up top ArrayList urllist = new ArrayList(); private void Form1_FormClosing(object sender, FormClosingEventArgs e) { StreamWriter sw = new StreamWriter("history.txt"); foreach (string temp in urllist) { sw.WriteLine(temp); } sw.Close(); sw.Dispose(); }
...then I got some ap, and shot a big ass lazar at everyone.
    (Edited 2010 Jan 27 at 22:39)     2010 Jan 27 at 22:16
sprinkles

Chrome Whore
2009 Sep 6 • 2431
10 ₧
The problem with this code, is each time you open the application is erases the history of the previous use.
...then I got some ap, and shot a big ass lazar at everyone.
    2010 Jan 28 at 12:42
Down Rodeo
Cap'n Moth of the Firehouse

Find the Hole II Participation Medal
2007 Oct 19 • 5258
57,583 ₧
There are a few ways you can open a file for writing. One is 'append', where the data is stuck on the end. Rather than the current erase and start over thingy.
Everyone stares when you walk in the room, they stare when you go....
    2010 Jan 28 at 16:23
sprinkles

Chrome Whore
2009 Sep 6 • 2431
10 ₧
I don't believe StreamWriter has an append method, but I also have to check if there is the same url already in the file. No it doesn't, but:


code
using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine("This"); sw.WriteLine("is Extra"); sw.WriteLine("Text"); }
...then I got some ap, and shot a big ass lazar at everyone.
    (Edited 2010 Jan 30 at 20:47)     2010 Jan 30 at 20:42

Pages: [1]
Forum and design copyright © 2008-2010 SuperJer.com