Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read the content of the file using Fileupload

Tags:

c#

asp.net

Is it possible to read the content of a file using Fileupload.

For example I want to save the XML file in Database , a user search the file using Fileupload and then click a button to save the content of the file in Database.

I tried this one but doesn't work

string s=Fileuploder1.Filecontent.tostring();

but no success,Do you have any idea?

like image 247
Baper Avatar asked Jun 15 '12 14:06

Baper


People also ask

What is the use of HttpPostedFileBase?

The HttpPostedFileBase class is an abstract class that contains the same members as the HttpPostedFile class. The HttpPostedFileBase class lets you create derived classes that are like the HttpPostedFile class, but that you can customize and that work outside the ASP.NET pipeline.

What is ASP FileUpload?

ASP.NET FileUpload control allows us to upload files to a Web Server or storage in a Web Form. The control is a part of ASP.NET controls and can be placed to a Web Form by simply dragging and dropping from Toolbox to a WebForm. The FileUpload control was introduced in ASP.NET 2.0.

What is importance of FileUpload control HasFile property?

The HasFile property gets a value indicating whether the FileUpload control contains a file to upload. Use this property to verify that a file to upload exists before performing operations on the file.


1 Answers

string inputContent;
using (StreamReader inputStreamReader = new StreamReader(InputFileUpload.PostedFile.InputStream))
{
    inputContent = inputStreamReader.ReadToEnd();
}
like image 173
Chris Schiffhauer Avatar answered Oct 25 '22 22:10

Chris Schiffhauer