Aras学习笔记 (38) 使用Asp.net批量上传附件到Aras并返回Item列表的通用方法
以下是批量上传的通用方法,重点是Item.attachPhysicalFile()属性的设置。
/// <summary> /// 文件上传 /// </summary> /// <param name="fileUploadList"></param> /// <returns></returns> public List<FILE> UploadFile(List<FileUploadModel> fileUploadList) { List<FILE> list = new List<FILE>(); try { if (fileUploadList != null) { for (int i = 0; i < fileUploadList.Count; i++) { Item item = innovator.newItem("File", "add"); item.setProperty("filename", fileUploadList[i].FileName); item.attachPhysicalFile(fileUploadList[i].FilePath); item = item.apply(); if (!item.isError()) { ModelHelper helper = new ModelHelper(); FILE file = helper.GetModelByItem<FILE>(item); if (file != null) { list.Add(file); } } } } } catch(Exception ex) { } return list; }
调用:
List<FileUploadModel> fileUploadList = new List<FileUploadModel>(); FileUploadModel file = new FileUploadModel(); file.FileName = this.FileUpload1.FileName; file.FilePath = Path.GetFullPath(this.FileUpload1.FileName); fileUploadList.Add(file);