Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C uwp中拒绝文件访问_C#_Uwp_Sha256_Filepicker - Fatal编程技术网

C# 在C uwp中拒绝文件访问

C# 在C uwp中拒绝文件访问,c#,uwp,sha256,filepicker,C#,Uwp,Sha256,Filepicker,我正在解决一个问题。我正在开发uwp应用程序,我需要使用filepicker获取所选文件的sha256哈希。 我已经完成了filepicker的部分,但当我使用filepicker从我的计算机中选择文件,并且我想检查此文件的哈希时,我会收到关于拒绝访问的错误消息。 有人解决了这样的问题吗?我想,当我用filepicker选择文件时,我可以访问它,对吗?。 我的问题是流的init,我按名称初始化了一个新流,但它不是这样工作的。 我发现,若我使用filepicker检查所有选择的文件,我将使用fil

我正在解决一个问题。我正在开发uwp应用程序,我需要使用filepicker获取所选文件的sha256哈希。 我已经完成了filepicker的部分,但当我使用filepicker从我的计算机中选择文件,并且我想检查此文件的哈希时,我会收到关于拒绝访问的错误消息。 有人解决了这样的问题吗?我想,当我用filepicker选择文件时,我可以访问它,对吗?

。 我的问题是流的init,我按名称初始化了一个新流,但它不是这样工作的。 我发现,若我使用filepicker检查所有选择的文件,我将使用filepicker返回的对象。 工作示例:

        var picker = new Windows.Storage.Pickers.FileOpenPicker();
        picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
        picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
        picker.FileTypeFilter.Add(".avi");
        picker.FileTypeFilter.Add(".mp4");
        picker.FileTypeFilter.Add(".mpeg");
        picker.FileTypeFilter.Add(".mov");
        picker.FileTypeFilter.Add(".mkv");

        IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();
        if (files.Count > 0)
        {
            // doing some needed staff

            StringBuilder output = new StringBuilder("Picked files:\n\n");

            // Application now has read/write access to the picked file(s)
            foreach (StorageFile file in files)
            {
                output.Append(file.Name + "\n");

                using (IRandomAccessStream filestream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    output.Append("File SHA256 hash -> " + BytesToString(Sha256.ComputeHash(filestream.AsStreamForRead())) + "\n\n");
                    await filestream.FlushAsync();
                }
            }
            this.filePickerInfo.Text = output.ToString();                
        }
        else
        {
            this.filePickerInfo.Text = "Operation cancelled.";                
        }    

至少在访问文件的位置显示代码。另外,选择一个文件只是意味着,您选择了它,没有进一步的断言,比如它是可访问的,它仍然存在,等等。选择一个文件证明的唯一一件事是您有权读取目录中包含的文件名。没什么了。@nyrguds-你说得不对。如果您使用filepicker选择文件,您将获得所选文件的读写权限。@Nyerguds-来自官方文档-检查-@Nyerguds-它可以完美地工作。若从计算机中选择文件,则可以对其进行读/写访问。