//2
 public SuperFile(int _id)
 {
     BLL.t_file   file  = new BLL.t_file();
     Model.t_file filem = file.GetModel(_id);
     _fileName  = filem.file_title;
     _fileTitle = filem.file_Name;
     _fileDir   = new  BLL.t_filecategory().GetModel(Convert.ToInt32(filem.file_catefory_ID)).filec_path;
 }
Exemple #2
0
        protected Boolean UploadFile(HttpPostedFile _file)
        {
            string fileName = _file.FileName;
            string sqlwhere = " file_title like '%" + fileName + "%'";

            DataSet datas = new BLL.t_file().GetList(sqlwhere);

            if (datas != null && datas.Tables[0].Rows.Count > 0)
            {
                ((HttpPostedFile[])Session["postedFiles"])[i] = null;
                string js = "alert('文件已存在');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", js, true);
                return(false);
            }
            string FileType_Name, _fname, FileType_Id, FileType_Path, _title, _fPath;


            FileType_Name = Path.GetExtension(_file.FileName).ToLower(); //获取文件扩展名
            FileType_Id   = "1";                                         //默认文件类型
            FileType_Path = "~/_uploadFiles/other/";                     //默认本地存储路径
            string sql = " file_ext like '%" + FileType_Name + "%'";     //通过文件扩展名查找文件类型

            BLL.t_filecategory filecategory = new BLL.t_filecategory();
            DataSet            ds           = filecategory.GetList(sql);

            Model.t_filecategory t_Filecategory = new Model.t_filecategory();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                t_Filecategory.filec_ID   = Convert.ToInt32(dr["filec_ID"]);
                t_Filecategory.filec_name = dr["filec_name"].ToString();
                t_Filecategory.filec_path = dr["filec_path"].ToString();
                t_Filecategory.file_ext   = dr["file_ext"].ToString();
                FileType_Id   = t_Filecategory.filec_ID.ToString();
                FileType_Path = t_Filecategory.filec_path;
            }
            _title = Path.GetFileName(_file.FileName);
            _fname = DateTime.Now.ToOADate() + FileType_Name;
            _fPath = MapPath(FileType_Path) + _fname;
            try
            {
                //创建没有存在的目录
                Directory.CreateDirectory(MapPath(FileType_Path));
                _file.SaveAs(_fPath);
            }
            catch
            {  }

            if (File.Exists(_fPath))
            {
                _fname = Path.GetFileName(_fname);
                Model.t_file file = new Model.t_file();
                file.file_catefory_ID = t_Filecategory.filec_ID;
                file.file_date        = DateTime.Now;
                file.file_Name        = _fname;
                file.file_title       = _title;

                BLL.t_file addfile = new BLL.t_file();
                if (!addfile.Add(file))
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }