本文介绍了SharePoint:如何以编程方式向列表项添加附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
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... }如何将普通文件转换为字节数组?
How do I convert a normal file to a byte array?
推荐答案 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,0,System.Convert.ToInt32(fs.Length)); //Close the File Stream fs.Close(); item.Attachments.Add(attachment.Name, ImageData); }更多推荐
SharePoint:如何以编程方式向列表项添加附件?
发布评论