Click here to Skip to main content
15,561,246 members
Home / Discussions / C#
   

C#

 
GeneralRe: Desktop Calender Repost Pin
0x3c01-Mar-09 7:27
0x3c01-Mar-09 7:27 
AnswerRe: Desktop Calender Repost Pin
AKNR Chandra Sekhar19-Mar-09 9:47
AKNR Chandra Sekhar19-Mar-09 9:47 
QuestionSaving User and Application Settings in WinForms Pin
Sokka9328-Feb-09 22:29
Sokka9328-Feb-09 22:29 
AnswerRe: Saving User and Application Settings in WinForms Pin
ABitSmart1-Mar-09 1:30
ABitSmart1-Mar-09 1:30 
GeneralRe: Saving User and Application Settings in WinForms Pin
Sokka931-Mar-09 1:54
Sokka931-Mar-09 1:54 
AnswerRe: Saving User and Application Settings in WinForms Pin
Henry Minute1-Mar-09 2:23
Henry Minute1-Mar-09 2:23 
QuestionFile Not Found Exception Handling Pin
Lim Yuxuan28-Feb-09 22:29
Lim Yuxuan28-Feb-09 22:29 
AnswerRe: File Not Found Exception Handling Pin
0x3c01-Mar-09 0:16
0x3c01-Mar-09 0: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 2:27
Lim Yuxuan1-Mar-09 2:27 
Questionbuilding network in form of a graph Pin
sunnyk8628-Feb-09 21:52
sunnyk8628-Feb-09 21:52 
AnswerRe: building network in form of a graph Pin
Yusuf28-Feb-09 22:16
Yusuf28-Feb-09 22:16 
AnswerRe: building network in form of a graph Pin
Eytukan1-Mar-09 3:41
Eytukan1-Mar-09 3:41 
Questiontoolbar moving Pin
shefa' isied28-Feb-09 21:42
shefa' isied28-Feb-09 21:42 
AnswerRe: toolbar moving Pin
Yusuf28-Feb-09 22:17
Yusuf28-Feb-09 22:17 
QuestionSocket Pin
mrithula828-Feb-09 21:39
mrithula828-Feb-09 21:39 
AnswerRe: Socket Pin
Yusuf28-Feb-09 22:22
Yusuf28-Feb-09 22:22 
GeneralRe: Socket Pin
mrithula828-Feb-09 23:47
mrithula828-Feb-09 23:47 
GeneralRe: Socket Pin
0x3c01-Mar-09 0:23
0x3c01-Mar-09 0:23 
GeneralRe: Socket Pin
mrithula81-Mar-09 0:39
mrithula81-Mar-09 0:39 
GeneralRe: Socket Pin
0x3c01-Mar-09 0:54
0x3c01-Mar-09 0:54 
GeneralRe: Socket Pin
mrithula81-Mar-09 18:22
mrithula81-Mar-09 18:22 
GeneralRe: Socket Pin
mrithula81-Mar-09 19:48
mrithula81-Mar-09 19:48 
QuestionHow to Copy Form in Project ? Pin
E_Gold28-Feb-09 21:12
E_Gold28-Feb-09 21:12 
AnswerRe: How to Copy Form in Project ? Pin
Yusuf28-Feb-09 22:26
Yusuf28-Feb-09 22:26 
GeneralRe: How to Copy Form in Project ? Pin
E_Gold28-Feb-09 23:13
E_Gold28-Feb-09 23: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.