Display Data from Drive D: in the Gridview

43 Views Asked by At

I have a gridview that displays data from drive D:

Code:

ObservableCollection<Book> datasource = new ObservableCollection<Book>();
        Book book = new Book();
    book.Name = file.DisplayName.ToString().Replace("_", " ");
        try
        {
            string thumbPath = @"D:\Kipin\thumb\komik";
            StorageFolder komikthumb = await StorageFolder.GetFolderFromPathAsync(thumbPath);
            thumbFile = await komikthumb.GetFileAsync(file.Name.ToString() + ".png");
            string path1 = komikthumb.Path;
            string filePath = Path.Combine(path1, file.Name.ToString() + ".png");
            if (System.IO.File.Exists(filePath))
            {
                book.Image = thumbFile.Path;
            }
    catch
    {}
    }
 datasource.Add(book);
 this.komikGridView.ItemsSource = datasource;

Book.cs:

public class Book
    {
        public string Name { get; set; } }
        public string Image { get; set; }
    }

The code above does not succeed in displaying data from D in the gridview and get error message: Exception thrown: 'System.UnauthorizedAccessException' in System.Private.CoreLib.dll.

I have also added a declaration to the package as shown below: declaration

How to handle it?

0

There are 0 best solutions below