【发布时间】:2015-03-13 17:08:56
【问题描述】:
我的应用程序出现一些问题,可以下载音乐文件列表。我正在尝试设置以下文件夹结构。音乐库 > 艺术家 > 发行名称。开始下载时,第一首歌曲的文件夹结构设置正确。一旦第二次下载开始,在尝试创建第二个子文件夹(版本名称)时,我总是会收到 File Not found 异常。这是我的代码。
private async Task StartDownload(List<DownloadData> data)
{
foreach (DownloadData song in data)
{
// Set the source of the download
Uri source = new Uri(song.downloadUrl);
// Create folder stucture
StorageFolder artistFolder;
try
{
artistFolder = await KnownFolders.MusicLibrary.CreateFolderAsync(song.artistName, CreationCollisionOption.OpenIfExists);
}
catch
{
throw;
}
StorageFolder releaseFolder;
try
{
releaseFolder = await artistFolder.CreateFolderAsync(song.releaseName, CreationCollisionOption.OpenIfExists);
}
catch
{
throw; // Exception Thrown here
}
// Create file
StorageFile destinationFile;
try
{
destinationFile = await releaseFolder.CreateFileAsync(song.fileName, CreationCollisionOption.GenerateUniqueName);
}
catch
{
throw;
}
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
List<DownloadOperation> requestOperations = new List<DownloadOperation>();
requestOperations.Add(download);
await HandleDownloadAsync(download, true);
}
}
我不知道为什么它第一次奏效,但第二首歌却失败了。
【问题讨论】:
-
你为什么有这么多
catch{throw;}。要么抓住并做某事,要么根本不抓住。 -
@juharr 我不知道如何处理异常。这就是我问这个问题的原因。
-
根据docs
CreateFileAsyncthrowsFileNotFoundExceptionif "文件夹名称包含无效字符,或者文件夹名称格式不正确。"那么song.releaseName的值是多少呢? -
好收获。发布名称中有几个“/”。那么我唯一的选择是删除那些吗?
标签: c# windows-8 windows-phone-8.1