微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/csharp/97617.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐