Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Write read data to file using network stream

Posted on 2004-09-02
6
Medium Priority
?
406 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

886 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