在Web加载项中获取Outlook附件信息

问题描述 投票:0回答:1

我有一个在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-2019 outlook-web-addins
1个回答
0
投票

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

//这是代码

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

//将附件加载到Azure服务器fileAttachment.Load(appPatch + fileAttachment.Name);

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

© www.soinside.com 2019 - 2024. All rights reserved.