Save the file in Wordpad not in Notepad using VB.net

M

Maya

Hey, there!

I'm new to vb.net and it seems I wouldn't be able to solve this
without help.
I have a pipe delimited file that has to be saved in txt format
so it could be accepted by my DTS package.
If I open and save the file manualy in Wordpad - it works.
(not in Notepad otherwise formatting is changed and DTS package
won't accept it.)

File.Copy(strPath,strTxtPath) method of System.IO - creates the copy
of the file with .txt extension as needed,but format is like in
notepad - all screwed.
I need the file to be opened and saved in Wordpad format
programmaticaly.

I'd really appreciate if anyone who knows how to do it let me know.

Thank you very much.
 
M

Maya

Jeff Levinson said:
I'm not sure exactly what the problem you're having, but
you can solve it by putting your text in a RichTextBox
control. Then call the Save method of the control. This
will save a file in rtf format which I believe is the
internal format used by wordpad (99% certain) but in any
case it will preserver any formatting. You can also copy
and paste Word docs into the richtextbox so you don't
have to code any of word's functionality.

Hope that helps.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"


Thank you, Jeff, for your reply.
I've tried RichTextBOx control too - it didn't work.
My original file has extension .px.
I've created the file with the same name .txt first and
then I've used SaveFile method of RichTextBox control.
Somehow it cleared the data in the file.

I will try to reference excel object and open the file with xls
extension and then save it as text then.

It's like a nightmare.
For some reason DTS cannot find delimiter if the file isn't saved in wordpad
or with other text format but not notepad.

Thank you again,


Maya
 
M

Maya

Jeff Levinson said:
I'm not sure exactly what the problem you're having, but
you can solve it by putting your text in a RichTextBox
control. Then call the Save method of the control. This
will save a file in rtf format which I believe is the
internal format used by wordpad (99% certain) but in any
case it will preserver any formatting. You can also copy
and paste Word docs into the richtextbox so you don't
have to code any of word's functionality.

Hope that helps.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"

Strange,
I replied back to this message in the morning and it's not here.

Anyway,
I've tried RichTextBox.SaveFile method too.
It clears up the file instead of saving in the format I need.

I found the solution by using Excel object.
I open the file with excel and save it as txt afterwards.
It saves it as with Wordpad.

Thank you very much for your reply.
 
R

Roy Osherove

You should look into saving the file with the proper encoding.
I suspect that your file I/O is saving the file in the default system
encoding(probably Unicode)
and what you need is ASCII or something similar.

You need to explicitly write the file with a specific encoding(from
System.Text.Encoding).
You need to write it using a StreamWriter object.
here's the code to get you started:

Dim fs As FileStream = File.Create("MyFileName")

'I specify the encoding with which the file will be written in the second
constructor parameter

Dim writer As StreamWriter = New StreamWriter(fs,
System.Text.Encoding.ASCII)

writer.Write(MyText)

writer.Close()



Should be short and simple after that.
 

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