Solved

Write read data to file using network stream

Posted on 2004-09-02
6
377 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 18

Expert Comment

by:armoghan
ID: 11973036
0
 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Keyboard 2 34
performance tune IIS 10 on win 2016 that only runs one website 4 62
InputLanguage 1 26
List<PaisEntity> - show some 1 24
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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