gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:26:54 24 4
gpt4 key购买 nike

我有以下代码:

  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,0,System.Convert.ToInt32(fs.Length));

//Close the File Stream
fs.Close();

item.Attachments.Add(attachment.Name, ImageData);


}

关于c# - SharePoint:如何以编程方式将附件添加到列表项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1334695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com