By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,734 Members | 832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,734 IT Pros & Developers. It's quick & easy.

Streamwriter not creating file -- sometimes

P: n/a
I'm using the following code to write some text to a file:

objWriter = New StreamWriter(FullPath, True, System.Text.Encoding.ASCII)
For nRow = 1 To sData.Length - 1
objWriter.WriteLine(sData(nRow))
Next nRow
objWriter.Flush()
objWriter.Close()

When I run this in the IDE, it works. When I compile it and run the EXE, it
doesn't give any errors, but it doesn't create the file either. I've tried
putting a message box in the loop, and the data is acutally there. I've put
this in a try/catch block, but it doesn't catch any error.

I've tried creating a setup package, building it, then running the setup.
Same behavior.

I've also tried just objWriter = New StreamWriter(FullPath), same behavior.

What am I doing wrong? Any ideas or suggestions at all would be
appreciated!
Thanks,
---Selden McCabe


Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Here's some additional information:

The code with the streamwriter was in a separate Class project which was
added to my solution. So this code was running in a DLL separate from the
main executable.

When I copied the code from this class into the form's button_click event,
it worked.

So, for some reason, having the code in a separate DLL causes the problem.

Any ideas why?

Thanks again,
---Selden
Nov 21 '05 #2

P: n/a
Here's some additional information:

The code with the streamwriter was in a separate Class project which was
added to my solution. So this code was running in a DLL separate from the
main executable.

When I copied the code from this class into the form's button_click event,
it worked.

So, for some reason, having the code in a separate DLL causes the problem.

Any ideas why?

Thanks again,
---Selden
Nov 21 '05 #3

P: n/a
I'd say double check the value of the FullPath variable and make sure
the file is being written where you think it is.

How is the FullPath variable being constructed?

Nov 21 '05 #4

P: n/a
I'd say double check the value of the FullPath variable and make sure
the file is being written where you think it is.

How is the FullPath variable being constructed?

Nov 21 '05 #5

P: n/a
Are you referencing the DLL correctly?

Is it necessary to have a streamwriter in a seperate DLL?
Nov 21 '05 #6

P: n/a
Hi Selden,

Have you tried Chris's suggestion?
I agree with Chris's suggestion that the FullPath is not the destination
dir you means.
To verify it, you may try to use a Console.WriteLine(FullPath) to write the
string out to confirm it.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #7

P: n/a
It's not creating file because of your second parameter. That parameter you have set to true, which is "Append" to existing file.

If the file doesn't exist, it's not going to create it. You need to first check to see if it exist. If it exists, then the second parameter needs to be TRUE otherwise set it for FALSE!

From http://www.developmentnow.com/g/38_2...-sometimes.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.