首页 > 解决方案 > 在 Web 加载项中获取 Outlook 附件信息

问题描述

我有一个在 Azure 上运行的 Outlook Web 插件。我正在使用控制器从 Outlook Exchange 服务器获取 Outlook 附件详细信息(这工作正常)。获得附件详细信息后,我调用一个 .cs 类来提取附件信息(名称、大小等)。我能够获取附件名称,但不能获取附件大小和内容。请参阅下面的代码。

这太疯狂了,我可以获取 System.IO.FileInfo 并引用名称但不能引用长度 - 当我引用长度时出现此错误找不到文件 'D:\home\site\wwwroot\AWS_Knowledge.docx'

我完全不知所措-为什么我能够获得名称而不是其他信息,例如(长度)。欢迎任何帮助 - 谢谢

public static OutLookAttachment(FileAttachment fileAttachment)
{
//I have tried all these differenct approaches to get the file info - 
//the below code return a local D:\.... path
string attachmentName1 = System.IO.Path.GetFileName(fileAttachment.Name);
string attachmentName2 = System.IO.Path.Combine(System.IO.Path.GetTempPath(), 
fileAttachment.FileName);

//I settled with this code since this is running on Azure/Website
//Returns Website D:\home\site\wwwroot\AWS_Knowledge.docx* path/
string attachmentName = 
System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString(), 
fileAttachment.Name);`

/*get the file info*/
System.IO.FileInfo fi = new System.IO.FileInfo(attachmentName);

/*get file data*/
//this works
string n = fi.Name;

//this works
string fn = fi.FullName;

//I get the error here saying Could not find file 
'D:\home\site\wwwroot\AWS_Knowledge.docx'
long length = fi.Length;

/*if I reference the passed in attachment directly, I get the below results*/

//this works - I get the file name
string fileName = fileAttachment.Name;

//this returns 0 - basically no data
long fielSize = fileAttachment.Size;
}

标签: visual-studio-2019outlook-web-addins

解决方案


我解决了这个问题 - 基本上,获取网站路径并加载附件 - 不要忘记删除附件以避免您的网站加载附件。

//这里是代码

//获取应用路径字符串 appPatch = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString());

//加载附件到Azure Server fileAttachment.Load(appPatch + fileAttachment.Name);

//完成附件 - 从站点中删除 System.IO.File.Delete(fileAttachment.FileName);


推荐阅读