应该有个配置文件可以配置的吧?至少FCK是有个配置文件来配置界面..可上传的文件类型的...

解决方案 »

  1.   

    为了安全起见,需要限制上传的文件类型.可以写在配置文件中,或者是直接固定某些类型可以上传.附上传方法, /// <summary>
    /// 是否允许该扩展名上传
    /// </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;
    }
      

  2.   

    在FreeTextBox中加???怎么加那段代码,老兄!!!!!!
      

  3.   

    for(int   i   =   0;i <arrExtension.Length;i++) 

    if(strExtension.Equals(arrExtension[i])) 

    return   true; 



    return   false; 
    } 这里如果不在返回true的时候加break的话返回的永远是false