应该有个配置文件可以配置的吧?至少FCK是有个配置文件来配置界面..可上传的文件类型的...
解决方案 »
- asp.net/xml
- 读取数据库时,只能读取前两列的值
- iframe 内嵌页读 cookie
- 没有问题,散分:如何减少代码冗余
- 图片保存到数据库跟保存到硬盘性能相差很大吗?
- DS问题,,那里错了,'System.Data.DataTableCollection' 弄了半天都没有解决
- 如何对比日期?就像视实现过生日的功能!!
- 提供asp.net 2.0 + sql 2005 空间
- 解决方案里存在x86和x64平台项目,报错。
- 请教.net做锚点用什么工具啊?在哪里找?
- 问一个较难的问题,关于asp.net网页接收客户端以 chunked 编码POST过来的信息
- asp.net如何生成html页?
/// 是否允许该扩展名上传
/// </summary>
/// <param name="hifile"></param>
/// <returns></returns>
public static bool IsAllowedExtension(HtmlInputFile hifile)
{
string strOldFilePath = "",strExtension = ""; //允许上传的扩展名,可以改成从配置文件中读出
string[]arrExtension = {".doc",".rar",".zip",".htm",".mht",".html"};
// string ConfigarrExtension = System.Configuration.ConfigurationSettings.AppSettings[ "FileExtensionName" ];
// string[] arrExtension = ConfigarrExtension.Split(','); if(hifile.PostedFile.FileName != string.Empty)
{
strOldFilePath = hifile.PostedFile.FileName;
//取得上传文件的扩展名
strExtension = strOldFilePath.Substring(strOldFilePath.LastIndexOf("."));
//判断该扩展名是否合法
for(int i = 0;i<arrExtension.Length;i++)
{
if(strExtension.Equals(arrExtension[i]))
{
return true;
}
}
}
return false;
}/// <summary>
/// 上传文件并返回文件名,如果出现重名则自动+(1)(2)(3).....
/// </summary>
/// <param name=hifile>HtmlInputFile控件</param>
/// <param name=strAbsolutePath>绝对路径.</param>
/// <returns>返回的文件名即上传后的文件名</returns>
public int SaveFile(HtmlInputFile hifile,string strAbsolutePath)
{
string strOldFilePath = "",strExtension = "",strNewFileName = "",strNewFileNameCurr = "" ; // if(!IsAllowedExtension(hifile))
{
//该类文件不允许上传
return 1;
}
//如果上传文件的文件名不为空
if(hifile.PostedFile.FileName != string.Empty)
{
strOldFilePath = hifile.PostedFile.FileName; //取得上传文件名
strNewFileName = strOldFilePath.Substring(strOldFilePath.LastIndexOf(@"\")); strNewFileName = strNewFileName.Substring(0,strNewFileName.LastIndexOf(@".")); //取得上传文件的扩展名
strExtension = strOldFilePath.Substring(strOldFilePath.LastIndexOf("."));
//如果路径末尾为\符号,则直接上传文件
if(strAbsolutePath.LastIndexOf(@"\") == strAbsolutePath.Length)
{
if(File.Exists(strAbsolutePath + strNewFileName + strExtension))
{ strNewFileNameCurr = strNewFileName;
for(int i =1 ;i<10;i++)
{
strNewFileName = strNewFileName + "(" + i.ToString() + ")" ; if(!File.Exists(strAbsolutePath + strNewFileName + strExtension))
{
break;
}
strNewFileName = strNewFileNameCurr;
}
}
hifile.PostedFile.SaveAs(strAbsolutePath + strNewFileName + strExtension );
}
else
{
if(File.Exists(strAbsolutePath + @"\" + strNewFileName + strExtension))
{
strNewFileNameCurr = strNewFileName; for(int i =1;i<10;i++)
{
strNewFileName = strNewFileName + "(" + i.ToString() + ")"; if(!File.Exists(strAbsolutePath + @"\" + strNewFileName + strExtension))
{
break;
}
strNewFileName = strNewFileNameCurr;
}
}
hifile.PostedFile.SaveAs(strAbsolutePath + @"\" + strNewFileName + strExtension);
}
}
return 0;
}
{
if(strExtension.Equals(arrExtension[i]))
{
return true;
}
}
}
return false;
} 这里如果不在返回true的时候加break的话返回的永远是false