Solved

Write read data to file using network stream

Posted on 2004-09-02
6
390 Views
Last Modified: 2008-01-09
Hello;
My question is that, i read datas through network stream. (Using NNTP) What i need to learn is how do i create the file that has been read? I get datas into string builder, what sould i do to create the actual file ?
0
Comment
Question by:lexicon_dominus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 11970577
StringBuilder bu = "hello";

FileInfo t = new FileInfo("Arungg.txt");
    StreamWriter Tex =f.CreateText();
    Tex.WriteLine(bu.ToString());
    Tex.close;
    Console.WriteLine(" The Text file named Arungg is created ");
0
 
LVL 4

Author Comment

by:lexicon_dominus
ID: 11972478
Thank armoghan but i wasn't clear i think. The files are not text files they are .rar, .zip, .exe etc files. I know the file types before reading the datas.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 11973007
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 2

Accepted Solution

by:
sholodak earned 500 total points
ID: 11973267
If you are retrieving files off of a newsgroup and populating a StringBuilder, I'm assuming that these files are encoded with UUEncode/Base64/yEnc or something along those lines.  These algorithms allow for converting binary <--> ascii.

Have a look at this article:
http://www.codeproject.com/dotnet/TextCoDec.asp

The class is written in VB.NET, but if your not too concerned with whats under the hood, I'd just include a reference to the DLL and call the appropriate functions.  It can take care of encoding/decoding to/from files/strings.  

In your example, you would call something along the lines of:

DecodedFile[] newfiles = yEnc.Decode(stringbuilder.ToString(), @"C:\directory\for\files", 0);

Some of the other encoders/decoders don't take strings as inputs, only streams.  You could get around this by doing something like this:

string BuiltString = sb.ToString();
byte[] StringAsBytes = System.Text.Encoding.ASCII.GetBytes(BuiltString);
System.IO.MemoryStream ms = new System.IO.MemoryStream(StringAsBytes);
uue.Decode(ms, @"C:\directory\for\files");

Once the files are decoded, they should become RAR's and ZIP's again.

One other thing.  If you're dealing with Base64 encoding, .NET has functions to take care of this for you:
string encoded = Convert.ToBase64String(binaryBytes);
byte[] decoded = Convert.FromBase64String(stringVersion);

You might want to compare the performance of this with the one in the library above.  The library might just wrap around the .NET function.

-- One other note.  If you're on 2000 or XP with NTFS, the person running your program must have Write permission to the target directory.  If this is a web app, that would probably be IUSR_MACHINENAME.

Scott
0
 
LVL 4

Author Comment

by:lexicon_dominus
ID: 11974157
Thank you sholodak, that was what i was looking for...
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question