i want to read content of file.but these code is not helping.
string[] readText = File.ReadAllLines(path); this line is giving error.
protected void btnRead_Click(object sender, EventArgs e)
{
string path = fileupload1.PostedFile.FileName;
if (!string.IsNullOrEmpty(path))
{
string[] readText = File.ReadAllLines(path);
StringBuilder strbuild = new StringBuilder();
foreach (string s in readText)
{
strbuild.Append(s);
strbuild.AppendLine();
}
textBoxContents.Text = strbuild.ToString();
}
}
The
File.ReadAllTextfunction expects the file to exist on the specified location. You haven’t saved it on the server and yet you are attempting to read it. If you don’t need to save the uploaded file on the server you could read directly from the input stream.This will work for text files. If you want to parse some other formats such as Word documents you will need a library to do that.