c# - Xamarin Forms - 检查 Environment.SpecialFolder.DesktopDirectory 中是否存在文件

标签 c# xamarin.forms cross-platform

在 Xamarin Forms 中,我们如何检查 Environment.SpecialFolder.DesktopDirectory 是否包含文件?

我正在使用以下命令从 azure 存储下载图像并将它们显示在页面上,它工作正常但我只想在不存在文件时这样做。

_activityIndicator.IsRunning = true;
            var imgPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "");
            var blobList = await BlobStorageService.GetBlobs<CloudBlockBlob>("images");

            foreach (CloudBlockBlob b in blobList)
            {
                Image _image = new Image();
                imgPath = imgPath + b.Name;
                await b.DownloadToFileAsync(imgPath, FileMode.Create);

                StackLayout s = new StackLayout();
                _title.Text = b.Name;
                _image.Source = imgPath; 
                s.Children.Add(_title);
                s.Children.Add(_image);
                iStack.Children.Add(s);
            }

最佳答案

你可以检查文件是否存在:

 if (File.Exists(imgPath))
        {
           **Write Your Code**
        }

关于c# - Xamarin Forms - 检查 Environment.SpecialFolder.DesktopDirectory 中是否存在文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51764430/

相关文章:

linux - 在 UNIX 类型的操作系统中获取当前用户帐户的显示名称

javascript - 使用按钮显示一些文本 - JavaScript

c# - 在 C# 中挂起进程

c++ - 将数字(金额)转换为文字的免费跨平台库?

f# - 如何在 F# 中为 Xamarin.Forms 创建自定义渲染器

c# - Xamarin Forms 错误处理 - 消息中心警报未从数据存储中显示

c - 独立于平台获取文件大小 (C)

c# - 使用转换器中的资源

c# - XDocument 节点中的 Foreach

c# - 在 Xamarin forms pcl 项目中使用 HttpUtility