AppData \ Local \ Packages中下载的文件在UWP中自动删除

时间:2018-10-09 04:03:18

标签: uwp windows-10 ziparchive storagefile storagefolder

我正在以这种方式在UWP应用中下载一些.zip文件。

var rootFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("attachment", CreationCollisionOption.OpenIfExists );
        FileInfo fInfo;
        this.infoFiles.TryTake(out fInfo);

            StorageFile coverpic = await rootFolder.CreateFileAsync(fInfo.FileName, CreationCollisionOption.ReplaceExisting);

            try
            {
                System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
                Uri URI = new Uri(fInfo.Url);
                byte[] buffer = await client.GetByteArrayAsync(URI); // Download file
                using (Stream stream = await coverpic.OpenStreamForWriteAsync())
                    stream.Write(buffer, 0, buffer.Length); // Save


                StorageFile zipFile = await MyFileHelper.GetFileAsync(rootFolder, fInfo.FileName);


                if (fInfo.FileName.ToLower().Contains(".zip"))
                {
                    await UnZipFileAsync(zipFile, rootFolder).ConfigureAwait(false);
                    if (Instance.DownloadedNotification != null)
                    {

                        Instance.DownloadedNotification(fInfo.FileName);
                    }
                    if (await rootFolder.TryGetItemAsync("5301.zip") != null)
                    {
                        Debug.WriteLine("Soon after Download and Unzip finished 5301.zip exists");
                    }
                    else
                    {
                        Debug.WriteLine("Soon after Download and Unzip finished 5301.zip doesn't exists");
                    }




                }
                else
                {
                    if (Instance.DownloadedNotification != null)
                    {

                        Instance.DownloadedNotification(fInfo.FileName);
                    }
                    if (await rootFolder.TryGetItemAsync("5301.zip") != null)
                    {
                        Debug.WriteLine("Soon after Download and Unzip finished and file name doesn't contain \"zipFile\" 5301.zip exists");
                    }
                    else
                    {
                        Debug.WriteLine("Soon after Download and Unzip finished and file name doesn't contain \"zipFile\" 5301.zip doesn't exists");
                    }
                }


                // return coverpic;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception Occured--" + e.Message);
            }

我正在异步下载30多个文件。我下载了1个文件并保存。然后解压缩(实际上,我正在读取.zip文件的内容而不解压缩它。然后将包含的文件复制到根文件夹中)。成功复制后,我将下载第二个.zip文件。

我的问题是,在此循环进行期间,根文件夹中缺少一些已经下载的文件(根文件夹中缺少.zip文件和unzip文件)。 例如,假设下载并解压缩了5301.zip文件作为第一个文件。如果程序正在下载第十个文件(5310.zip),则缺少5301.zip文件和解压缩的文件。 我的文件正在下载到

  

C:\ Users \ myuser \ AppData \ Local \ Packages \ de187d8d-my-app-id-2b3b8a255c7b_tqgs61w0frgtm \ LocalState \ attachment

为什么会这样?请指导我解决此问题。 谢谢!

0 个答案:

没有答案