Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Read PostedFile Directly into a String Variable

Posted on 2004-11-01
1
Medium Priority
?
328 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
[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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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