这是一个文件类型检测的函数
private bool IsAllowedExtension(FileUpload hifile)
{
//FileUpload hifile = (FileUpload)this.FindControl(Filee);
System.IO.FileStream fs = new System.IO.FileStream(hifile.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
//未能找到文件“G:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\xxxx.jpg”。
//为什么这个路径会跑到安装目录下去了,而不是我选择文件的路径?
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();
}
catch
{ }
r.Close();
fs.Close();
if (fileclass == "255216" || fileclass == "7173")
//说明255216是jpg;
{
return true;
}
else
{
return false;
}
}
private bool IsAllowedExtension(FileUpload hifile)
{
//FileUpload hifile = (FileUpload)this.FindControl(Filee);
System.IO.FileStream fs = new System.IO.FileStream(hifile.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
//未能找到文件“G:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\xxxx.jpg”。
//为什么这个路径会跑到安装目录下去了,而不是我选择文件的路径?
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();
}
catch
{ }
r.Close();
fs.Close();
if (fileclass == "255216" || fileclass == "7173")
//说明255216是jpg;
{
return true;
}
else
{
return false;
}
}
解决方案 »
- Jquery的12030状态错误,百思不得其解啊
- 什么是解决方案
- Repeater绑定OjbectDataSource,打算如果返回的数据为空,则要显示“无数据”
- 在codebhind(cs文件)中如何将DropDownList进行非数据库的绑定赋值(附代码,几行)?
- 今天离开公司了,非常不舍,心里很难受,散分
- asp.net 2.0 cache 怎么操作
- FreetextBox 的html编辑功能如何去除
- 没分了,帮帮忙,谢谢各位!!
- 关于服务器端返回json数据的问题
- 为什么我新建一个web service的时候会出错呢?很烦阿!麻烦帮一帮手!
- 谁用过jeditable"就地编辑"的插件啊?怎么有问题啊?
- 隔段时间出现这个错:Could not load type from string value
string type = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();
if (type != "txt")
{ this.LblFile.Text = "请选择txt类型的文本文件";
return;
}
else
{
this.LblFile.Text = "";
} Stream stream = this.fuMessageContent.FileContent;
StreamReader reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("gb2312"));
string contents = "";
while (!reader.EndOfStream)
{
contents = reader.ReadToEnd(); }
this.txtMessageContent.Text = contents;
reader.Close();
stream.Close();
//未能找到文件“G:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\xxxx.jpg”。
//为什么这个路径会跑到安装目录下去了,而不是我选择文件的路径?