SharePoint:如何以编程方式向列表项添加附件?

编程入门 行业动态 更新时间:2024-10-09 01:20:17
本文介绍了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:如何以编程方式向列表项添加附件?

本文发布于:2023-11-05 02:55:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:附件   方式   列表   SharePoint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!