c# – SharePoint:如何以编程方式将附件添加到列表项?

前端之家收集整理的这篇文章主要介绍了c# – 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...

        }

如何将普通文件转换为字节数组?

解决方法

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); 


        }
原文链接:https://www.f2er.com/csharp/97617.html

猜你在找的C#相关文章