Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Diana - 05 Jul 2005 16:10 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.