?
Solved

Read PostedFile Directly into a String Variable

Posted on 2004-11-01
1
Medium Priority
?
330 Views
Last Modified: 2012-05-05
Hello;

I'm uploading a file through a form using a File server control.

The file uploads fine into memory, and I can save the file to disk using a line of code such as "MyFile.PostedFile.SaveAs...."

What I really want to do is that this entire file, and get it into a String variable (without having to save it to disk at all).  The contents of the file are just plain text with line breaks (no null characters or anything).  I'm pretty sure I'd use the MyFile.PostedFile.InputStream.Read method, but it looks like this method returns an integer, or perhaps an array of bytes.

So, I guess my question is..  How do I get the entire contents of a file uploaded through a File server control into a String variable, assuming the file contains no special characters other than line breaks.  I do NOT want to save the file to a disk first and then re-read it through an StreamReader object.

Thanks in advance,

Dan
0
Comment
Question by:dsulli2000
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 12469885
You could pass that stream to a StreamReader and either read it one line at a time (ReadLine) or all at once (ReadAll).  One of the constructors for a StreamReader takes a stream as the parameter, so you wouldn't have to save to disk first.  

The Read method returns the number of bytes read into the byte array buffer.

Bob

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

601 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