473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Streamwriter not creating file -- sometimes

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
7 3885
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
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
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
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
Are you referencing the DLL correctly?

Is it necessary to have a streamwriter in a seperate DLL?
Nov 21 '05 #6
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Majed | last post by:
Hi , all I'm trying to write unicode to a file for another app (not developed with vs2003) to read it. I used StreamWriter with unicode encoding.but I was surprised that the streamwriter adds FFFE...
0
by: notalent | last post by:
I'm having a problem with a very basic program. I'm creating a app in Visual Studio (2003) C# to zip up a collection of specified files & directories and save them to a certain location. I have...
1
by: Lars Hansen | last post by:
Hi This is probably pretty basic, but I have a problem with the access-level (local variable), when creating a new StreamWriter. I am trying to write some price information to a textfile - which...
5
by: Brendan Miller | last post by:
Hi, I have been having a problem writing the contents of a dataset to a .csv file. When I write to a .csv file and open it with either Excel or Wordpad the "french" characters are wrong. When I...
1
by: piotrek | last post by:
Hi. I would like to ask if there is a method to force streamwriter.writeline() to write line at the end of existing file, or should i have write the method for my own. PK
0
by: Selden McCabe | last post by:
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...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
2
by: sameer | last post by:
Hi, My very simple application VB.NET Visual Studio 2003 console application uses a log file to write some text to it. I am using StreamWriter object to create and open and then append text to...
4
by: Mads Westen | last post by:
Hi, I'm parsing some XML files, and converting them to CSV. I got x number of XML files in a directory, these files do I need to be converted and written to the same CSV file. My problem is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.