如何将图像或文件在任何位置复制或删除到UWP应用程序中的文件夹中

卡万·奥斯曼(Karwan E.Othman)

我试图将图像或文件从计算机复制到UWP Application的本地文件夹中,但尚未完成。我总是告诉文件访问被拒绝。我在Microsoft网站上搜索了google和UWP资源,并使用了从这些链接中获得的大多数方法。但是我还没有。

卡万·奥斯曼(Karwan E.Othman)

太谢谢你了 我找到了解决方案,您的回答很有用。

这是解决方案

这是上传按钮图片

        private async void BtnAddImage_OnClick(object sender, RoutedEventArgs e)
    {
        var imagePicker = new FileOpenPicker
        {
            ViewMode = PickerViewMode.Thumbnail,
            SuggestedStartLocation = PickerLocationId.Desktop,
            FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
        };


        var imageFile = await imagePicker.PickSingleFileAsync();
        if (imageFile == null)
        {
            return;
        }

        _storageFile = imageFile;
        _path = imageFile.Path;

        var dataPackage = new DataPackage();

        dataPackage.SetBitmap(RandomAccessStreamReference.CreateFromFile(imageFile));
        Clipboard.SetContent(dataPackage);




        var dataPackageView = Clipboard.GetContent();
        if (!dataPackageView.Contains(StandardDataFormats.Bitmap)) return;


        IRandomAccessStreamReference imageReceived = await dataPackageView.GetBitmapAsync();


        if (imageReceived == null) return;
        using (var imageStream = await imageReceived.OpenReadAsync())
        {
            var bitmapImage = new BitmapImage();
            bitmapImage.SetSource(imageStream);
            ImgSupplier.Source = bitmapImage;

        }

        StorageApplicationPermissions.FutureAccessList.Add(imageFile);
    }

重新运行路径

    private static string GetPath(string folderName)
    {

  var root = Windows.ApplicationModel.Package.Current.InstalledLocation.Path + @"\Assets\";

        var fullPath = Path.Combine(root, folderName);
        return fullPath;
    }

这是一个保存按钮

    private StorageFile _storageFile;   
    private async void BtnAddExpenditure_OnClick(object sender, RoutedEventArgs e)
    {
        var getPath = GetPath("Companies");

        var folder = await StorageFolder.GetFolderFromPathAsync(getPath);
        await _storageFile.CopyAsync(folder, Guid.NewGuid() + "." + _storageFile.FileType);
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将位图保存到Android中的应用程序文件夹

在创建DMG之前,将JPackage复制文件到应用程序的Resource文件夹中

Swift:首次运行应用程序时,如何将文件从应用程序包复制到“文档”文件夹

如何将应用程序生成的文件存储在Android的“下载”文件夹中?

UWP-应用程序文件夹中的图像Uri

创建预构建事件以将文件复制到Android应用程序中的资产文件夹

如何将资源文件夹从jar复制到程序文件中

如何将Digital Ocean应用程序文件夹复制到本地计算机?

如何在UWP应用程序的AppX中包含文件夹和文件?

如何将文件夹中的所有文件捆绑到VS2015中的UWP应用程序包中?

如何将节点应用程序的内容“构建”到名为“ dist”的文件夹中

如何将文件从特定文件夹复制到C#中的共享文件夹?

如何将Web应用程序中的文件夹与网站同步?

如何将下载的文件保存在应用程序内存的缓存文件夹中?

创建React应用程序-如何将pdf.worker.js文件从pdfjs-dist / build复制到项目的输出文件夹中?

如何将.NET Framework Console应用程序子文件夹复制到发行文件夹?

如何将文件从其他文件夹复制到WINDOWS中的单个位置?

要将图像从SD卡复制到Android应用程序的res / drawable文件夹中

如何将上载的文件存储到MVC应用程序中应用程序文件夹以外的位置

将文件包放入iOS应用程序中的特定文件夹位置

如何将图像从UIImagePickerController保存到应用程序文件夹?

如何将另一个应用程序的res文件夹导入到Android Studio中的应用程序?

在InternetExplorer中不删除ASP MVC应用程序的images文件夹中的图像

将文件拖放到应用程序中,然后将该文件复制到文件夹中

当 Dockerfile 存在于该文件夹中时,如何将任何文件夹复制到 Docker 容器?

UWP 应用程序:将图像从文件夹加载到图库而不锁定 .Net Core 中的文件

将文件复制到目标文件夹并删除任何不在源文件夹中的文件?

如何将文件夹中的文件复制到多个文件夹中

如何将文件保存到电子js中的应用程序文件夹