代码之家  ›  专栏  ›  技术社区  ›  DarkW1nter

XAMARIN窗体-检查文件是否存在于环境中。

  •  1
  • DarkW1nter  · 技术社区  · 6 年前

    在Xamarin表单中,如何检查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);
                }
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Jinesh Chhichhiya    6 年前

    您可以使用以下方法检查是否存在文件:

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