将电子邮件附件保存到 UNC 路径
我在为 Outlook 编写的 VSTO 加载项中有以下代码:
savefolder = Regex.Replace(Guid.NewGuid().ToString(), @"[- ]", String.Empty);
savepathfull = string.Format(@"{0}{1}", netloc, savefolder);
DirectoryInfo di = new DirectoryInfo(@savepathfull);
if (!(di.Exists))
Directory.CreateDirectory(@savepathfull);
removedFiles = new List<string>();
for (int d = attachs.Count; d > 0; d--)
{
if (attachs[d].Size > smallAttachment)
{
removedFiles.Add(attachs[d].FileName);
attachs[d].SaveAsFile(savepathfull);
}
}
一切正常,直到我尝试保存附件,此时我收到 UnauthorizedAccessException。我知道我的测试用户拥有该文件夹的完全权限,但我仍然收到此错误。
有想法吗?
谢谢。
I have the following code in a VSTO add-in I'm writing for Outlook:
savefolder = Regex.Replace(Guid.NewGuid().ToString(), @"[- ]", String.Empty);
savepathfull = string.Format(@"{0}{1}", netloc, savefolder);
DirectoryInfo di = new DirectoryInfo(@savepathfull);
if (!(di.Exists))
Directory.CreateDirectory(@savepathfull);
removedFiles = new List<string>();
for (int d = attachs.Count; d > 0; d--)
{
if (attachs[d].Size > smallAttachment)
{
removedFiles.Add(attachs[d].FileName);
attachs[d].SaveAsFile(savepathfull);
}
}
Everything works fine until I try to save the attachment, at which point I receive an UnauthorizedAccessException. I know that my test user has full rights to the folder, yet I still receive this error.
Ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
Attachment.SaveAsFile
时,您需要提供有效的文件名。您正在尝试保存到目录,而不是文件。请参阅 MSDN 了解参考代码。You need to provide a valid filename when calling
Attachment.SaveAsFile
. You are trying to save to a directory, not to a file. See MSDN for reference code.