的SharePoint:如何添加附件以编程列表项? [英] SharePoint: How to add an attachment to a list item programatically?
本文介绍了的SharePoint:如何添加附件以编程列表项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
SPList列表= web.Lists [this.ListName]
SPListItem项目= list.Items.Add();
现在我想要做的是:
的FileInfo [] =附件attachmentDirectory.GetFiles();
的foreach(附件中的FileInfo附件)
{
//从文件系统中的附件添加到列表项...
}
如何转换一个正常的文件字节数组?
解决方案
的foreach(附件中的FileInfo附件)
{
的FileStream FS =新的FileStream(attachment.FullName,FileMode.Open,FileAccess的。读);
//创建文件流长度
字节一个字节数组[] =的ImageData新的字节[fs.Length]从字节流
//读取块入字节数组
fs.Read(的ImageData,0,System.Convert.ToInt32(fs.Length));
//关闭文件流
fs.Close();
item.Attachments.Add(attachment.Name,的ImageData);
}
I have the following code:
SPList list = web.Lists[this.ListName];
SPListItem item = list.Items.Add();
now what I want to do is:
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:如何添加附件以编程列表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文