Click here to Skip to main content
15,884,933 members
Home / Discussions / C#
   

C#

 
GeneralRe: Desktop Calender Repost Pin
0x3c01-Mar-09 6:27
0x3c01-Mar-09 6:27 
AnswerRe: Desktop Calender Repost Pin
AKNR Chandra Sekhar19-Mar-09 8:47
AKNR Chandra Sekhar19-Mar-09 8:47 
QuestionSaving User and Application Settings in WinForms Pin
Sokka9328-Feb-09 21:29
Sokka9328-Feb-09 21:29 
AnswerRe: Saving User and Application Settings in WinForms Pin
ABitSmart1-Mar-09 0:30
ABitSmart1-Mar-09 0:30 
GeneralRe: Saving User and Application Settings in WinForms Pin
Sokka931-Mar-09 0:54
Sokka931-Mar-09 0:54 
AnswerRe: Saving User and Application Settings in WinForms Pin
Henry Minute1-Mar-09 1:23
Henry Minute1-Mar-09 1:23 
QuestionFile Not Found Exception Handling Pin
Lim Yuxuan28-Feb-09 21:29
Lim Yuxuan28-Feb-09 21:29 
AnswerRe: File Not Found Exception Handling Pin
0x3c028-Feb-09 23:16
0x3c028-Feb-09 23:16 
Your problem lies with the File.Create method. It returns a FileStream instantiation. Until you close the FileStream, you cannot read the file without requesting different access to it. Try something like this
void RetrieveData()
{
    Stream bookStream = new FileStream("books.txt", FileMode.OpenOrCreate);

    using(StreamReader booksReader = new StreamReader(bookStream))
    {
        //Do what you want with booksReader here, the using block will automatically close the streams to avoid memory leaks
    }
}

The trick here is creating a new FileStream with FileMode.OpenOrCreate. If the file exists, it is opened; if it doesn't exist, it is created and then opened. If you want to check whether the file is empty (it's pointless reading from an empty file), check whether bookStream.Length is equal to zero. This will also tell you if the file is newly created because the newly created file will be empty
GeneralRe: File Not Found Exception Handling Pin
Lim Yuxuan1-Mar-09 1:27
Lim Yuxuan1-Mar-09 1:27 
Questionbuilding network in form of a graph Pin
sunnyk8628-Feb-09 20:52
sunnyk8628-Feb-09 20:52 
AnswerRe: building network in form of a graph Pin
Yusuf28-Feb-09 21:16
Yusuf28-Feb-09 21:16 
AnswerRe: building network in form of a graph Pin
Eytukan1-Mar-09 2:41
Eytukan1-Mar-09 2:41 
Questiontoolbar moving Pin
shefa' isied28-Feb-09 20:42
shefa' isied28-Feb-09 20:42 
AnswerRe: toolbar moving Pin
Yusuf28-Feb-09 21:17
Yusuf28-Feb-09 21:17 
QuestionSocket Pin
mrithula828-Feb-09 20:39
mrithula828-Feb-09 20:39 
AnswerRe: Socket Pin
Yusuf28-Feb-09 21:22
Yusuf28-Feb-09 21:22 
GeneralRe: Socket Pin
mrithula828-Feb-09 22:47
mrithula828-Feb-09 22:47 
GeneralRe: Socket Pin
0x3c028-Feb-09 23:23
0x3c028-Feb-09 23:23 
GeneralRe: Socket Pin
mrithula828-Feb-09 23:39
mrithula828-Feb-09 23:39 
GeneralRe: Socket Pin
0x3c028-Feb-09 23:54
0x3c028-Feb-09 23:54 
GeneralRe: Socket Pin
mrithula81-Mar-09 17:22
mrithula81-Mar-09 17:22 
GeneralRe: Socket Pin
mrithula81-Mar-09 18:48
mrithula81-Mar-09 18:48 
QuestionHow to Copy Form in Project ? Pin
E_Gold28-Feb-09 20:12
E_Gold28-Feb-09 20:12 
AnswerRe: How to Copy Form in Project ? Pin
Yusuf28-Feb-09 21:26
Yusuf28-Feb-09 21:26 
GeneralRe: How to Copy Form in Project ? Pin
E_Gold28-Feb-09 22:13
E_Gold28-Feb-09 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.