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
we cannot directly read the file, instead of that we should save it in the project location. using the project file path we can read with the help of stream reader.
var filePath = Path.Combine(Server.MapPath("~/Document"), fileName);
file.SaveAs(filePath);
if (!string.IsNullOrEmpty(filePath))
{
using (StreamReader sr = new StreamReader(Path.Combine(Server.MapPath("~/Document"), fileName)))
{
while (sr.Peek() >= 0)
{
strbuild.AppendFormat(sr.ReadLine());
}
}
}
for more details:http://www.infinetsoft.com/Post/How-to-read-text-file-using-fileupload-control-in-asp-net-MVC/1245