want to create empty textfile and add both string and binary conte

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!
I am trying to find out how to create an empty textfile (.txt) and add
content made of two different types of formats; string and binary, and then
save it.

The idea is to first add the "dokumentheadtext" as a string,
second to add the "documentbody" as binary by extracting the content from a
uploaded httpPostedFile (.txt or .doc for example) and convert it to binary,
third I want to be able to add the "documentfoot" as a string.

Is this possible? Anyone have any good suggestions how this is best made, or
at least some good advise?

Would be most thankful...
Regards, Diana from Sweden
 
Diana said:
I am trying to find out how to create an empty textfile (.txt) and add
content made of two different types of formats; string and binary, and then
save it.

As soon as you're adding binary content, you're *not* creating a text
file, unless you're also converting the binary content to text (eg
using Base64).
 
Hi

I would use the System.IO.FileStream to create a buffer for a text file then
System.IO.StreamWriter to write all the data.

Transform the bytes to strings, something like:
_________________________________________________
Imports System.IO
Public Module Class1
Dim bytes() As Byte = {0, 24, 245, 32, 32}
Dim text As String = "Hola"

Private testfile As String = "Test.txt"
Public Sub Main()
' Create the new, empty data file.
Dim fs As New FileStream(testfile, FileMode.Create)
Console.WriteLine("{0} file created/overwritten", testfile)

text &= Convert.ToBase64String(bytes)

' Create the writer for text.
Dim sw As New StreamWriter(fs)
' Write text
sw.Write(text)
sw.Close()

'Close buffer
fs.Close()
End Sub
End Module
_________________________________________________

Hope it helps, nice name Diana :-)
Greetings from Switzerland
 
*lol*
Thank you so much, your suggestion was similar to what I alreday had tried
but I realized I missed out on the 'ToBase64String'...
I'll try it right away! Thanks again!
Hugz, D
 
Back
Top