0
當用戶通過將文件類型與我的應用程序相關聯來選擇文件時,我試圖複製PDF文件。在onfileactivated方法讀取文件時獲取未經授權的異常
不幸的是我獲得未經授權的異常,當嘗試複製文件
async protected override void OnFileActivated(FileActivatedEventArgs e)
{//IReadOnlyList<IStorageItem>
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
if (!rootFrame.Navigate(typeof(MainPage)))
{
throw new Exception("Failed to create initial page");
}
}
StorageFolder magazinefolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("pdffolder", CreationCollisionOption.OpenIfExists);
IAsyncAction asyncAction = Windows.System.Threading.ThreadPool.RunAsync(
(workItem) =>
{
foreach (IStorageItem tm in e.Files)
{
File.Copy(tm.Path, magazinefolder.Path);
}
// this.loadlibrary();
});
var p = rootFrame.Content as MainPage;
// p.AddFileCall(e.Files);
// Ensure the current window is active
Window.Current.Activate();
}
假設你'tm'是一個StorageFile,你有沒有試過'tm.CopyAsync(magazinefolder);'? – Romasz
是的,但同樣的錯誤 –
而當你不重定向工作到ThreadPool - 只需運行'await(e.Files.FirstOrDefault()as StorageFile).CopyAsync(magazineFolder);'你也會得到一個異常?如果您獲得了有效的StorageFile,您是否曾試過並檢查過?是否有可能分享一個示例項目? – Romasz