In my ASP.NET MVC website, I have to read a txt file with some names and emails separeted by ';'. After that, I have to save each line of this txt file to database.
Googling around, I've found some snippets, but in all of them I have to use the txt file path.
But, how can I get this path? This file could be anywhere in a user's machine!
Thanks!!
You cannot get the full path of an uploaded file. This would be a privacy violation for the user that uploaded the file.
Instead, you'll need to read the Request.Files that have been uploaded. For example:
HttpPostedFile file = Request.Files[0];
using (StreamReader reader = new StreamReader(file.InputStream))
{
while ((string line = reader.ReadLine()) != null)
{
string[] addresses = line.Split(';');
// Do stuff with the addresses
}
}