Streamwriter not creating file -- sometimes

S

Selden McCabe

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
 
S

Selden McCabe

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
 
C

Chris Dunaway

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?
 
G

Guest

Are you referencing the DLL correctly?

Is it necessary to have a streamwriter in a seperate DLL?
 
P

Peter Huang [MSFT]

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.
 
M

Michael Schutte

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top