title: OpenXML to Read Document
body: <p>So I have put an excel document in my assets folder for testing.  And I am working on a test project just to see how the code works.</p>
  
  <p>If I run the following code:</p>
  
  <pre><code>public async void TestAsync()
          {
              StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
              StorageFile sampleFile = await storageFolder.GetFileAsync(@"Assets\Generator_Run_Data.xlsx");
          byte[] result;
          using (Stream stream = await sampleFile.OpenStreamForReadAsync())
          {
              using (var memoryStream = new MemoryStream())
              {
  
                  stream.CopyTo(memoryStream);
                  result = memoryStream.ToArray();
              }
          }
      }
  </code></pre>
  
  <p>to which I get a result {byte[48347]}</p>
  
  <p>But on the following code I get an error:</p>
  
  <pre><code>public async static void CreateSpreadsheetWorkbook()
          {
              StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
              storageFolder = await storageFolder.GetFolderAsync(@"Assets");
  
          // Create a spreadsheet document by supplying the filepath.
          // By default, AutoSave = true, Editable = true, and Type = xlsx.
          SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(storageFolder.Path, SpreadsheetDocumentType.Workbook);
  
          // Add a WorkbookPart to the document.
          WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
          workbookpart.Workbook = new Workbook();
  
          // Add a WorksheetPart to the WorkbookPart.
          WorksheetPart worksheetPart = workbookpart.AddNewPart&lt;WorksheetPart&gt;();
          worksheetPart.Worksheet = new Worksheet(new SheetData());
  
          // Add Sheets to the Workbook.
          Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild&lt;Sheets&gt;(new Sheets());
  
          // Append a new worksheet and associate it with the workbook.
          Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
          sheets.Append(sheet);
  
          workbookpart.Workbook.Save();
  
          // Close the document.
          spreadsheetDocument.Close();
      }
  </code></pre>
  
  <p>The error being:</p>
  
  <pre><code>System.UnauthorizedAccessException
    HResult=0x80070005
    Message=Access to the path 'C:\Users\xxxxx\source\repos\GeneratedCode\GeneratedCode\bin\x86\Debug\AppX\Assets' is denied.
    Source=System.IO.FileSystem
    StackTrace:
     at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
     at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
     at System.IO.MultiplexingWin32WinRTFileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
     at System.IO.Packaging.ZipPackage..ctor(String path, FileMode packageFileMode, FileAccess packageFileAccess, FileShare share)
     at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare)
     at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.CreateCore(String path)
     at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Create(String path, SpreadsheetDocumentType type, Boolean autoSave)
     at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Create(String path, SpreadsheetDocumentType type)
     at GeneratedCode.MainPage.&lt;CreateSpreadsheetWorkbook&gt;d__2.MoveNext() in C:\Users\xxxxx\source\repos\GeneratedCode\GeneratedCode\MainPage.xaml.cs:line 68
  </code></pre>
  
  <p>So the folder is accessible in one case and not in another.  Help me to understand please.</p>
  
  <p>Tried this code as well:</p>
  
  <pre><code>using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(sampleFileString, true))
  </code></pre>
  
  <p>and also received an error:</p>
  
  <pre><code>System.UnauthorizedAccessException
    HResult=0x80070005
    Message=Access to the path 'C:\Users\xxxxx\source\repos\GeneratedCode\GeneratedCode\bin\x86\Debug\AppX\Assets\Generator_Run_Data.xlsx' is denied.
    Source=System.IO.FileSystem
    StackTrace:
     at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
     at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
     at System.IO.MultiplexingWin32WinRTFileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
     at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
     at System.IO.Packaging.ZipPackage..ctor(String path, FileMode packageFileMode, FileAccess packageFileAccess, FileShare share)
     at System.IO.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare)
     at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(String path, Boolean readWriteMode)
     at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable, OpenSettings openSettings)
     at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(String path, Boolean isEditable)
     at GeneratedCode.MainPage.Spreadsheet(String[] args) in C:\Users\xxxxx\source\repos\GeneratedCode\GeneratedCode\MainPage.xaml.cs:line 105
     at GeneratedCode.MainPage..ctor() in C:\Users\xxxxx\source\repos\GeneratedCode\GeneratedCode\MainPage.xaml.cs:line 42
     at GeneratedCode.GeneratedCode_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage() in C:\Users\xxxxx\source\repos\GeneratedCode\GeneratedCode\obj\x86\Debug\XamlTypeInfo.g.cs:line 178
     at GeneratedCode.GeneratedCode_XamlTypeInfo.XamlUserType.ActivateInstance() in C:\Users\xxxxx\source\repos\GeneratedCode\GeneratedCode\obj\x86\Debug\XamlTypeInfo.g.cs:line 333
  </code></pre>