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
Jon Skeet [C# MVP] - 05 Jul 2005 17:57 GMT
> 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).

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Andres Armengol - 05 Jul 2005 19:03 GMT
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
Diana - 06 Jul 2005 09:01 GMT
*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
> Hi
>
[quoted text clipped - 30 lines]
> Hope it helps, nice name Diana :-)
> Greetings from Switzerland