c# – SharePoint:如何以编程方式将附件添加到列表项?
发布时间:2020-12-15 18:07:30 所属栏目:百科 来源:网络整理
导读:我有以下代码: SPList list = web.Lists[this.ListName]; SPListItem item = list.Items.Add(); 现在我想做的是: FileInfo[] attachments = attachmentDirectory.GetFiles(); foreach (FileInfo attachment in attachments) { // Add the attachment from
我有以下代码:
SPList list = web.Lists[this.ListName]; SPListItem item = list.Items.Add(); 现在我想做的是: FileInfo[] attachments = attachmentDirectory.GetFiles(); foreach (FileInfo attachment in attachments) { // Add the attachment from file system to the list item... } 如何将普通文件转换为字节数组? 解决方法foreach (FileInfo attachment in attachments) { FileStream fs = new FileStream(attachment.FullName,FileMode.Open,FileAccess.Read); // Create a byte array of file stream length byte[] ImageData = new byte[fs.Length]; //Read block of bytes from stream into the byte array fs.Read(ImageData,System.Convert.ToInt32(fs.Length)); //Close the File Stream fs.Close(); item.Attachments.Add(attachment.Name,ImageData); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |