Ejemplo n.º 1
0
        public string UploadFile()
        {
            HttpPostedFileBase file = Request.Files["myfile"];


            FillTool fillTool = new FillTool();


            string date = fillTool.getNowDate();

            int type = fillTool.getFileType(file.FileName);

            //文件名添加guid防止文件名重复
            var gu = Guid.NewGuid();


            var fileName = file.FileName;
            var filePath = Server.MapPath("~/Temp/" + "username");
            int size     = file.ContentLength;



            //根据用户名创建文件夹
            if (System.IO.Directory.Exists(Server.MapPath("~/Temp/" + "username")) == false)//如果不存在就创建file文件夹
            {
                System.IO.Directory.CreateDirectory(Server.MapPath("~/Temp/" + "username"));
            }

            if (System.IO.File.Exists(filePath + "/" + fileName))
            {
                return("已存在");
            }


            file.SaveAs(Path.Combine(filePath, fileName));

            //decimal size = fillTool.getDirectorySize(filePath + "/" + fileName, "MB");

            //文件实体类
            API.Model.fileOne fileOne = new API.Model.fileOne();
            fileOne.tb_int         = gu;
            fileOne.tb_name_before = file.FileName;
            fileOne.tb_name_now    = fileName;
            fileOne.tb_date        = date;
            fileOne.tb_size        = size;
            fileOne.tb_username    = "******";
            fileOne.tb_userid      = 1;
            fileOne.tb_type        = type;
            fileOne.tb_address     = filePath;
            fileOne.tb_projectid   = 2;
            fileOne.tb_project     = "b";


            fone.AddB(fileOne);


            return("上传成功");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public API.Model.fileOne DataRowToModel(DataRow row)
        {
            API.Model.fileOne model = new API.Model.fileOne();
            if (row != null)
            {
                if (row["tb_int"] != null && row["tb_int"].ToString() != "")
                {
                    model.tb_int = new Guid(row["tb_int"].ToString());
                }

                if (row["tb_name_before"] != null && row["tb_name_before"].ToString() != "")
                {
                    model.tb_name_before = row["tb_name_before"].ToString();
                }

                if (row["tb_name_now"] != null && row["tb_name_now"].ToString() != "")
                {
                    model.tb_name_now = row["tb_name_now"].ToString();
                }

                if (row["tb_date"] != null && row["tb_date"].ToString() != "")
                {
                    model.tb_date = row["tb_date"].ToString();
                }

                if (row["tb_size"] != null && row["tb_size"].ToString() != "")
                {
                    model.tb_size = int.Parse(row["tb_size"].ToString());
                }

                if (row["tb_username"] != null && row["tb_username"].ToString() != "")
                {
                    model.tb_username = row["tb_username"].ToString();
                }

                if (row["tb_userid"] != null && row["tb_userid"].ToString() != "")
                {
                    model.tb_userid = int.Parse(row["tb_userid"].ToString());
                }

                if (row["tb_type"] != null && row["tb_type"].ToString() != "")
                {
                    model.tb_type = int.Parse(row["tb_type"].ToString());
                }

                if (row["tb_address"] != null && row["tb_address"].ToString() != "")
                {
                    model.tb_address = row["tb_address"].ToString();
                }

                if (row["tb_projectid"] != null && row["tb_projectid"].ToString() != "")
                {
                    model.tb_projectid = int.Parse(row["tb_projectid"].ToString());
                }

                if (row["tb_project"] != null && row["tb_project"].ToString() != "")
                {
                    model.tb_project = row["tb_project"].ToString();
                }
            }
            return(model);
        }