I am working on a project and I need to upload a CSV file and read it. I am working in Visual Studio 2010 and MVC3 and C# language.
If I am to use html fileuplaod control, how I am suppose to take the uploaded file and read it in the client side itself without saving the file in the server. Do I have to use the jquery? I have searched but did not get solution to meet my requirements. I am new to MVC3 and CSV file handling and quite confused.
*What is the easiest way to upload a .csv file and read it in order to save it in the database.
A clear solution would be highly appreciated.Thanks.
What you can do is save the file on server, then after you read the content from them you can delete the file.
I think there is a no way you can read the from client side. You must upload it on ur server to read that.
using (StreamReader CsvReader = new StreamReader(input_file))
{
string inputLine = "";
while ((inputLine = CsvReader.ReadLine()) != null)
{
values.Add(inputLine.Trim().Replace(",", "").Replace(" ", ""));
}
CsvReader.Close();
return values;
}
You should be able to access the data without saving it - using the InputStream property
http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.inputstream.aspx
and this (see Paulius Zaliaduonis answer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With