首页 > 解决方案 > 无法访问 UWP 中的视频库

问题描述

我觉得我错过了一些东西,但不确定它是什么。

我有两个 UWP 应用程序,我已将它们设置为使用视频库作为临时存储位置。一个应用程序运行良好,另一个应用程序说它没有权限。据我所知,编码完全相同。我验证了应用程序的功能在两个应用程序中的设置也是相同的。

关于还有什么可以看的任何建议?

非工作代码:

public static async Task GetFileAsync()
        {
            var (authResult, message) = await Authentication.AquireTokenAsync();
            var httpClient = new HttpClient();
            HttpResponseMessage response;
            var request = new HttpRequestMessage(HttpMethod.Get, MainPage.fileurl);
            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
            response = await httpClient.SendAsync(request);
            byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
            StorageLibrary videoLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
            string saveFolder = videoLibrary.SaveFolder.Path;
            string saveFileName = App.Date + "-" + App.Shift + ".xlsx";
            saveLocation = saveFolder + "\\" + saveFileName;

            using (MemoryStream stream = new MemoryStream())
            {
                stream.Write(fileBytes, 0, (int)fileBytes.Length);
                using (spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
                {
                    await Task.Run(() =>
                    {
                        File.WriteAllBytes(saveLocation, stream.ToArray());
                        return TaskStatus.RanToCompletion;
                    });
                }
            }
        }

        public async static Task UpdateCell(string docName, string text,
            uint rowIndex, string columnName)
        {
            StorageLibrary videoLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
            string saveFolder = videoLibrary.SaveFolder.Path;
            string saveFileName = App.Date + "-" + App.Shift + ".xlsx";
            saveLocation = saveFolder + "\\" + saveFileName;

            await Task.Run(() =>
            {
                using (spreadsheetDoc = SpreadsheetDocument.Open(saveLocation, true))
                {
                    WorksheetPart worksheetPart =
                        GetWorksheetPartByName(spreadsheetDoc, "DC11Rounds");

                    if (worksheetPart != null)
                    {
                        Cell cell = GetCell(worksheetPart.Worksheet,
                                                    columnName, rowIndex);
                        cell.CellValue = new CellValue(text);
                        cell.DataType =
                            new EnumValue<CellValues>(CellValues.String);

                        worksheetPart.Worksheet.Save();
                    }
                }
                return TaskStatus.RanToCompletion;
            });
        }

工作代码:

public static async Task GetFileAsync()
        {
            var (authResult, message) = await Authentication.AquireTokenAsync();
            var httpClient = new HttpClient();
            HttpResponseMessage response;
            var request = new HttpRequestMessage(HttpMethod.Get, MainPage.fileurl);
            request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
            response = await httpClient.SendAsync(request);
            byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();
            StorageLibrary videoLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
            string saveFolder = videoLibrary.SaveFolder.Path;
            string saveFileName = App.Date + "-" + App.Shift + ".xlsx";
            saveLocation = saveFolder + "\\" + saveFileName;

            using (MemoryStream stream = new MemoryStream())
            {
                stream.Write(fileBytes, 0, (int)fileBytes.Length);
                using (spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
                {
                    await Task.Run(() =>
                    {
                        File.WriteAllBytes(saveLocation, stream.ToArray());
                        return TaskStatus.RanToCompletion;
                    });
                }
            }
        }

        public async static Task UpdateCell(string docName, string text,
            uint rowIndex, string columnName)
        {
            StorageLibrary videoLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);
            string saveFolder = videoLibrary.SaveFolder.Path;
            string saveFileName = App.Date + "-" + App.Shift + ".xlsx";
            saveLocation = saveFolder + "\\" + saveFileName;

            await Task.Run(() =>
            {
                using (spreadsheetDoc = SpreadsheetDocument.Open(saveLocation, true))
                {
                    WorksheetPart worksheetPart =
                        GetWorksheetPartByName(spreadsheetDoc, "DC6Rounds");

                    if (worksheetPart != null)
                    {
                        Cell cell = GetCell(worksheetPart.Worksheet,
                                                    columnName, rowIndex);
                        cell.CellValue = new CellValue(text);
                        cell.DataType =
                            new EnumValue<CellValues>(CellValues.String);

                        worksheetPart.Worksheet.Save();
                    }
                }
                return TaskStatus.RanToCompletion;
            });
        }

截屏: 在此处输入图像描述

Appmanifast 文件

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap mp iot rescap">
  <Identity Name="0724a480-5e3e-4cd4-a2a5-0c7305491ce3" Publisher="CN=tkrupka" Version="1.0.0.0" />
  <mp:PhoneIdentity PhoneProductId="0724a480-5e3e-4cd4-a2a5-0c7305491ce3" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
  <Properties>
    <DisplayName>DC11Rounds</DisplayName>
    <PublisherDisplayName>tkrupka</PublisherDisplayName>
    <Logo>Assets\StoreLogo.png</Logo>
  </Properties>
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
  </Dependencies>
  <Resources>
    <Resource Language="x-generate" />
  </Resources>
  <Applications>
    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="DC11Rounds.App">
      <uap:VisualElements DisplayName="DC11Rounds" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="DC11Rounds" BackgroundColor="transparent">
        <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
        </uap:DefaultTile>
        <uap:SplashScreen Image="Assets\SplashScreen.png" />
      </uap:VisualElements>
    </Application>
  </Applications>
  <Capabilities>
    <Capability Name="internetClient" />
    <Capability Name="privateNetworkClientServer" />
    <uap:Capability Name="enterpriseAuthentication" />
    <uap:Capability Name="videosLibrary" />
    <rescap:Capability Name="broadFileSystemAccess" />
  </Capabilities>
</Package>

工作文件

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
  <Identity Name="9e9838f0-1e60-482a-b922-189cc5e928f9" Publisher="CN=XXXXXX" Version="1.0.0.0" />
  <mp:PhoneIdentity PhoneProductId="9e9838f0-1e60-482a-b922-189cc5e928f9" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
  <Properties>
    <DisplayName>DC6Rounds</DisplayName>
    <PublisherDisplayName>XXXXXX</PublisherDisplayName>
    <Logo>Assets\StoreLogo.png</Logo>
  </Properties>
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
  </Dependencies>
  <Resources>
    <Resource Language="x-generate" />
  </Resources>
  <Applications>
    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="DC6Rounds.App">
      <uap:VisualElements DisplayName="DC6Rounds" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="DC6Rounds" BackgroundColor="black">
        <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
        </uap:DefaultTile>
        <uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="black" />
      </uap:VisualElements>
    </Application>
  </Applications>
  <Capabilities>
    <Capability Name="internetClient" />
    <Capability Name="privateNetworkClientServer" />
    <uap:Capability Name="enterpriseAuthentication" />
    <uap:Capability Name="videosLibrary" />
  </Capabilities>
</Package>

尝试添加受限功能时出现此错误:

严重性代码描述项目文件行抑制状态警告命名空间' http://schemas.microsoft.com/appx/manifest/foundation/windows10 '中的元素'Capabilities'在命名空间' http://schemas '中具有无效的子元素'Capability' .microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities '。预期的可能元素列表:命名空间“http://schemas.microsoft.com/appx/manifest/foundation/windows10”中的“CapabilityChoice”以及命名空间“ http://schemas.microsoft.com/appx ”中的“Capability /manifest/uap/windows10 '以及命名空间中的'能力'' http://schemas.microsoft。'以及命名空间'http://schemas.microsoft.com/appx/manifest/uap/windows10/4'中的'Capability'以及命名空间' http://schemas.microsoft.com/appx '中的'Capability' /manifest/uap/windows10/6 '以及命名空间' http://schemas.microsoft.com/appx/manifest/uap/windows10/7 '中的'Capability'以及命名空间' http:/中的'Capability' /schemas.microsoft.com/appx/manifest/uap/windows10/3以及命名空间中的“能力” http://schemas.microsoft.com/appx/manifest/uap/windows10/2以及“命名空间中的 CustomCapabilityChoice' http://schemas.microsoft。com/appx/manifest/foundation/windows10 ' 以及命名空间中的 'CustomCapability'http://schemas.microsoft.com/appx/manifest/uap/windows10/4 '以及'Dev.... DC11Rounds C:\Users\XXXXXX\GitVault\DC11Rounds\DC11Rounds\DC11Rounds\Package.appxmanifest 31

试过这个:

    //StorageLibrary storageLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Documents);
    //string saveFolder = storageLibrary.SaveFolder.Path;
    StorageFolder saveFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

收到这个:

消息=找不到路径“C:\Users\XXXXXX\GitVault\DC11Rounds\DC11Rounds\DC11Rounds\bin\x86\Debug\AppX\Windows.Storage.StorageFolder\20181205-Days.xlsx”的一部分。

意识到我犯了一个错误并忘记了 .path。所以我仍然有同样的问题。

标签: c#uwpvideo-library

解决方案


检查应用程序对视频库的访问权限是否未在“设置”应用程序中被禁用。转到开始设置,然后选择隐私视频。右侧的应用程序列表应包含您的应用程序,您需要验证切换是否设置为On

设置隐私中的应用


推荐阅读