0

I feel like I am missing something, but not sure what it is.

I have two UWP apps which I have setup to use the video library as a temporary storage location. One app works fine and the other app says it does not have permission. From what I can tell the coding is exactly the same. I verified that the capabilities of the app is setup the same in both apps as well.

Any suggestions on what else to look at?

Non-working code:

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;
            });
        }

Working Code:

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;
            });
        }

Screenshot: enter image description here

Appmanifast File

<?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>

Working File

<?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>

Getting this error when trying to add restricted capabilities:

Severity Code Description Project File Line Suppression State Warning The element 'Capabilities' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid child element 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities'. List of possible elements expected: 'CapabilityChoice' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/6' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/7' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/3' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/2' as well as 'CustomCapabilityChoice' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'CustomCapability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Dev.... DC11Rounds C:\Users\XXXXXX\GitVault\DC11Rounds\DC11Rounds\DC11Rounds\Package.appxmanifest 31

Tried this:

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

Received this:

Message=Could not find a part of the path 'C:\Users\XXXXXX\GitVault\DC11Rounds\DC11Rounds\DC11Rounds\bin\x86\Debug\AppX\Windows.Storage.StorageFolder\20181205-Days.xlsx'.

Realized I made a mistake and forgot a .path. SO I still have the same issue.

CET
  • 262
  • 1
  • 2
  • 12
  • Could you please post the code of the `Package.appxmanifest` file? You can just open it as an XML file instead of the built-in Visual Studio designer – Martin Zikmund Dec 05 '18 at 16:26
  • @MartinZikmund I have added the file as requested. – CET Dec 05 '18 at 16:30
  • 1
    Does the element for the working app contain exactly the same thing? Isn't there broadFileSystemAccess? Also, could you try uninstalling and reinstalling the app? – Martin Zikmund Dec 05 '18 at 16:45
  • @MartinZikmund unloading had no effect. Added working code. – CET Dec 05 '18 at 16:50
  • You just say the two UWP apps have the same code, but if one is a general UWP app, one may be a converted UWP app? – Xie Steven Dec 06 '18 at 06:12
  • @XavierXie-MSFT I created both from scratch. Used the first app code to design the second app code. – CET Dec 06 '18 at 11:05
  • 1
    @CET OK. What're your OS build version and project target version? – Xie Steven Dec 07 '18 at 02:31
  • @XavierXie-MSFT Version 10.0.16299 Build 16299 on system. Bad app has min & max at 10.0.16299.0. Good app has minimum at 10.0.10586.0. – CET Dec 10 '18 at 20:48
  • @XavierXie-MSFT If I try to change the minimum of the bad app I start getting errors. Severity Code Description Project File Line Suppression State Error XBF syntax error '0x09C4' : Property Not Found. Check if the property you are setting in XAML exists in the minimum version of the platform being specified in the project (TargetPlatformMinVersion) – CET Dec 10 '18 at 20:49
  • 1
    @CET The error information has explained very clearly. You need to check if the property is available in min version. – Xie Steven Dec 11 '18 at 02:14
  • @XavierXie-MSFT and MartinZikmund So after all of this, I added the broadFileSystemAccess, used document library, changed my minimum target value, and made the editorial changes because of the change in Minimum target. The project now works! Thanks to both of you. Not sure how to mark as Answered since most of this is in comments. – CET Dec 11 '18 at 18:56

2 Answers2

2

Check if the application's access to videos library hasn't been disalbed in the Settings app. Go to Start, Settings, there select Privacy and Videos. The list of apps on the right should contain your app and you need to verify if the toggle is set to On.

Apps in Settings Privacy

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • The interesting thing here, is that I do not have that setting. Would that not prevent both apps from working if I have not added it before? – CET Dec 05 '18 at 18:18
  • Company only has us at 16299, so that option is not available to me because of not having 17063. – CET Dec 05 '18 at 19:41
  • I would not be surprised if both apps failed, because using the classic File IO is not allowed in restricted locations, including libraries, but as you say one app works and the other does not, that is very confusing... – Martin Zikmund Dec 05 '18 at 22:29
  • See end of original message. Tried something else, but it failed, but differently. – CET Dec 05 '18 at 22:47
0

I added the broadFileSystemAccess, used document library, changed my minimum target value, and made the editorial changes because of the change in Minimum target. The project now works! Thanks to both of you. Not sure how to mark as Answered since most of this is in comments

CET
  • 262
  • 1
  • 2
  • 12