if (GetUploadFileContent.PostedFile.InputStream.Length < 1)
{
Msg.Text = "请选择文件";
return;
}
string FileName = GetUploadFileContent.FileName;//上传文件文件名
string FilePath = GetUploadFileContent.PostedFile.FileName;//上传文件完整路径+文件名
string fileExtName = FileName.Substring(FileName.LastIndexOf(".") + 1, 3);
if (fileExtName == "txt" || fileExtName == "TXT" || fileExtName == "xml" || fileExtName == "XML")
{
int FileLen = GetUploadFileContent.PostedFile.ContentLength;//获取上传文件的大小
byte[] input = new byte[FileLen];
System.IO.Stream UpLoadStream = GetUploadFileContent.PostedFile.InputStream;
UpLoadStream.Read(input, 0, FileLen);
UpLoadStream.Position = 0;
System.IO.StreamReader sr = new System.IO.StreamReader(UpLoadStream, System.Text.Encoding.Default);
Msg.Text = sr.ReadToEnd();
if (Msg.Text != "")
{
//此处的Msg.Text 就是文本中文件内容!
}
}
else
{
Msg.Text = "文件为空!";
return;
}
sr.Close();
UpLoadStream.Close();
UpLoadStream = null;
sr = null;
}
else
{
Msg.Text = "请选择要求的类型的文件!";
return;
}