/// <summary> /// 创建新的 file 对象。 /// </summary> /// <param name="id">Id 属性的初始值。</param> /// <param name="fileName">fileName 属性的初始值。</param> /// <param name="filePath">filePath 属性的初始值。</param> /// <param name="userId">UserId 属性的初始值。</param> /// <param name="foldId">FoldId 属性的初始值。</param> public static file Createfile(global::System.Int32 id, global::System.String fileName, global::System.String filePath, global::System.Int32 userId, global::System.Int32 foldId) { file file = new file(); file.Id = id; file.fileName = fileName; file.filePath = filePath; file.UserId = userId; file.FoldId = foldId; return(file); }
/// <summary> /// 增加一个文件实体 /// </summary> /// <param name="fold"></param> /// <returns></returns> public bool addFile(file fold) { using (FoldDBEntities ef = new FoldDBEntities()) { ef.file.AddObject(fold); int resuit = ef.SaveChanges(); if (resuit > 0) { return(true); } else { return(false); } } }
protected void btnUP_Click(object sender, EventArgs e) { string fileName = ""; string savePath = "/UserFold/"; if (this.fileUP.HasFile) { HttpPostedFile file = this.fileUP.PostedFile; fileName = file.FileName; string extension = Path.GetExtension(fileName).ToLower(); if (extension == ".jpg" || extension == ".gif" || extension == ".doc" || extension == ".docx") { if (!Directory.Exists(Server.MapPath(savePath))) { Directory.CreateDirectory(Server.MapPath(savePath)); } if (File.Exists(Server.MapPath(savePath + fileName))) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('已经存在相同的文件')</script>"); return; } this.fileUP.SaveAs(Server.MapPath(savePath + fileName)); } try {///第一次插入数据 Fold modelFold = new Fold(); modelFold.Depth = 0; //modelFold.FatherId //第一层fatherId没有值 modelFold.FoldName = savePath; modelFold.UserId = 1; int id = bs.addFold(modelFold); if (id > 0) { file modelfile = new file(); modelfile.fileName = fileName; modelfile.filePath = savePath + fileName; modelfile.FoldId = id; bs.addFile(modelfile); } } catch (Exception ex) { } } }
/// <summary> /// 用于向 file EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddTofile(file file) { base.AddObject("file", file); }