最多知道我可以将附件加载到内存中,我知道它的正确原因我可以打印文件的名称。我需要的是将此附件转换为图像对象,我将稍后添加到sharepoint图片库。但是忘记了我知道如何做到的共享点部分,我被困在加载附件后如何将其转换为图像的部分。我不想将图像保存在磁盘中,因为这不是我已经将它们加载到内存中的一点。
foreach (Item item in findResults.Items)
{
if (item is EmailMessage && item.HasAttachments)
{
EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
foreach (Attachment attachment in message.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
// Load the file attachment into memory and print out its file name.
fileAttachment.Load();
Console.WriteLine("Attachment name: " + fileAttachment.Name);
//this is where i would create the image of object but dont know how
}
}
}
}
答案 0 :(得分:0)
您已拥有FileAttachment对象,甚至可以访问其中一个属性。您只需执行下一步操作,不仅可以访问Name
,还可以访问Content
。
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
fileAttachment.Load();
byte[] fileContent = fileAttachment.Content;
}
这将为您提供attachemnts上的内容,作为一个字节数组。我不记得Sharepoint API想要接收什么,但它是这个字节数组或者你可以很容易地构建它的东西。