visual-studio-2019 - 在 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;
}
解决方案
我解决了这个问题 - 基本上,获取网站路径并加载附件 - 不要忘记删除附件以避免您的网站加载附件。
//这里是代码
//获取应用路径字符串 appPatch = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory.ToString());
//加载附件到Azure Server fileAttachment.Load(appPatch + fileAttachment.Name);
//完成附件 - 从站点中删除 System.IO.File.Delete(fileAttachment.FileName);
推荐阅读
- postscript - PDF OPI(Open Prepress Interface),用高分辨率图像替换低分辨率代理的步骤是什么?
- powershell - 快捷方式列表脚本
- android - 来自路由的颤振屏幕在本地化之前加载
- java - 字符串包含与列表包含
- matlab - Ubuntu 上的 MATLAB 运行时安装程序
- git - git如何自动合并?
- angular - 如何处理这个错误?'类型中缺少索引签名......'
- angular - 使用 ctrl-v 将图像粘贴到输入文件中
- java - Mono::then 返回 null
- java - Spring Boot- Itext - 错误 - PTagWorker 类型的 Worker 无法处理 DivTagWorker