Click here to Skip to main content
15,885,216 members
Home / Discussions / C#
   

C#

 
GeneralRe: index += 1 equals index + 2 ? Pin
Lodeclaw25-Feb-09 12:25
Lodeclaw25-Feb-09 12:25 
QuestionTransfer a txt file Pin
bar300025-Feb-09 11:05
bar300025-Feb-09 11:05 
AnswerRe: Transfer a txt file Pin
Alan Balkany25-Feb-09 11:18
Alan Balkany25-Feb-09 11:18 
GeneralRe: Transfer a txt file Pin
bar300025-Feb-09 11:28
bar300025-Feb-09 11:28 
AnswerRe: Transfer a txt file Pin
Christian Graus25-Feb-09 11:27
protectorChristian Graus25-Feb-09 11:27 
GeneralRe: Transfer a txt file Pin
bar300025-Feb-09 11:35
bar300025-Feb-09 11:35 
GeneralRe: Transfer a txt file Pin
vaghelabhavesh25-Feb-09 13:49
vaghelabhavesh25-Feb-09 13:49 
AnswerRe: Transfer a txt file Pin
Luc Pattyn25-Feb-09 11:45
sitebuilderLuc Pattyn25-Feb-09 11:45 
Hi,

your code seems completely wrong to me. Here are some of the problems:

- a SaveFileDialog is meant for the user to enter a new filename or choose an existing filename, or to cancel the intended operation. To do that correctly you should compare the return value of ShowDialog() against DialogResult.OK (you compare FileName with empty string, I doubt that is equivalent) and use the FileName value as the path of the output file (you don't use the value at all).

- (the part shown of) your code does not declare, create or use writer and file except for closing it, so at best something gets written somewhere else, and some (which?) file gets closed; anyway changing the state of writer and file should not be a side effect of the saveDialog.FileName != "" test, the writer and the file operation should only exist inside the code block following that test, and nowhere else.

- declaring a FileStream and opening a file inside the code block of the if statement, while not using that stream, does not make any sense. Once the if-block is done, the stream is out of scope, hence useless.

- if your code creates a FileDialog, it should also dispose of it; the using statement is the easiest way of doing it right.


I suggest you have a look at some CodeProject articles; a lot of them describe small applications that do load and save some data from and to a file, using OpenFileDialog and SaveFileDialog. Just use these as search terms in the CP search facility.

If you don't fully understand the FileDialog class, read its documentation; if you still feel uncomfortable, go buy and study an introductory book on the language of your choice. It will teach you the basics in a systematic way.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles]

- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


modified on Sunday, June 12, 2011 8:38 AM

AnswerRe: Transfer a txt file Pin
harold aptroot25-Feb-09 12:54
harold aptroot25-Feb-09 12:54 
AnswerRe: Transfer a txt file Pin
Luc Pattyn25-Feb-09 13:15
sitebuilderLuc Pattyn25-Feb-09 13:15 
AnswerRe: Transfer a txt file [modified] Pin
Megidolaon25-Feb-09 21:59
Megidolaon25-Feb-09 21:59 
QuestionRTF Fields have a gap between them when placed against each other. Pin
Ryan Esteves25-Feb-09 9:47
professionalRyan Esteves25-Feb-09 9:47 
GeneralRe: RTF Fields have a gap between them when placed against each other. Pin
Lodeclaw25-Feb-09 12:30
Lodeclaw25-Feb-09 12:30 
GeneralRe: RTF Fields have a gap between them when placed against each other. Pin
Ryan Esteves26-Feb-09 4:19
professionalRyan Esteves26-Feb-09 4:19 
AnswerRe: RTF Fields have a gap between them when placed against each other. Pin
Ryan Esteves3-Mar-09 6:00
professionalRyan Esteves3-Mar-09 6:00 
QuestionDynamically passing a variable list of parameters to a Generic delegate? Pin
Steve Holdorf25-Feb-09 9:32
Steve Holdorf25-Feb-09 9:32 
QuestionRe: Dynamically passing a variable list of parameters to a Generic delegate? Pin
Steve Holdorf25-Feb-09 10:16
Steve Holdorf25-Feb-09 10:16 
Questionwill firewall bolck the tcp listner ? Pin
Mubeen.asim25-Feb-09 8:40
Mubeen.asim25-Feb-09 8:40 
AnswerRe: will firewall bolck the tcp listner ? Pin
Christian Graus25-Feb-09 9:09
protectorChristian Graus25-Feb-09 9:09 
GeneralRe: will firewall bolck the tcp listner ? Pin
Mubeen.asim25-Feb-09 9:12
Mubeen.asim25-Feb-09 9:12 
GeneralRe: will firewall bolck the tcp listner ? Pin
EliottA25-Feb-09 10:36
EliottA25-Feb-09 10:36 
QuestionConverting grid values to lower case for update Pin
alwaysgull25-Feb-09 8:26
alwaysgull25-Feb-09 8:26 
QuestionConverting grid values to lower case for update Pin
alwaysgull25-Feb-09 8:09
alwaysgull25-Feb-09 8:09 
AnswerRe: Converting grid values to lower case for update Pin
Rutvik Dave25-Feb-09 8:36
professionalRutvik Dave25-Feb-09 8:36 
GeneralRe: Converting grid values to lower case for update Pin
alwaysgull25-Feb-09 11:18
alwaysgull25-Feb-09 11:18 

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.