Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Write read data to file using network stream

Posted on 2004-09-02
6
Medium Priority
?
395 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Accepted Solution

by:
sholodak earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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