gpt4 book ai didi

c# - 编写电子邮件时访问拒绝异常 Windows 8.1 C#

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:01 24 4
gpt4 key购买 nike

private async Task<StorageFile> GetCsvFile()
{
var localFolder = KnownFolders.DocumentsLibrary;
var file = await localFolder.CreateFileAsync("NRBcatalogue.csv", Windows.Storage.CreationCollisionOption.ReplaceExisting);

String rk = "";
for (int i = 0; i < k1.Count; i++)
{
rk += k1[i] + "\n";
}
await Windows.Storage.FileIO.WriteTextAsync(file, rk);
return file;
}

private async void AppBarButton_Click_1(object sender, RoutedEventArgs e)
{
EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient("brk27.007@gmail.com"));
email.Subject = "NRB Catalogue";
var file = await GetCsvFile(); //Error occured here
email.Attachments.Add(new EmailAttachment(file.Name, file));
await EmailManager.ShowComposeNewEmailAsync(email);
}

The Error Details are: A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll. An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll but was not handled in user code. Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

最佳答案

您正在尝试访问您没有权限的位置 var localFolder = KnownFolders.DocumentsLibrary;

这是有效的异常,因为您无法从 Windows Phone 应用程序访问 DocumentsLibrary 位置。此位置仅适用于 Windows 应用商店应用。您可以使用其他位置,但在使用之前请确保您已将此位置添加为应用程序 list 中的功能。供引用查询This Link .

因此必须选择您的应用可以访问的其他位置。例如 LocalFolder , IsolatedStorage 等。对于 Localfolder 只需通过以下代码更改您的访问文件夹代码。

 var localFolder =  Windows.Storage.ApplicationData.Current.LocalFolder;

希望它能解决您的问题。干杯:)

关于c# - 编写电子邮件时访问拒绝异常 Windows 8.1 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24596969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com