1

I tried to find files located in the root project of my Blazor Client WebAssembly project. While it works when executed locally on my computer, it doesn't work when hosted on Azure.

When executed locally, I got 1

When executed on Azure, I got 0 (no access denied errors of things like that)

To be more complete, I will have some files needed to fill an initial blank database.

If I cannot access files in the project folder, then I will go for a Blob Azure Storage. I would like to clarify that this is only a test project for myself.

enter image description here

Bronzato
  • 9,438
  • 29
  • 120
  • 212
  • 1
    You're looking for files in the application's current working directory, assuming that this is the same directory which holds your application. This may be true (and VS sets this by default), but it may not be. You can get the directory containing your application using something like `Path.GetDirectoryName(typeof(QuizController).Assembly.Location)` – canton7 Jun 09 '20 at 09:23
  • 1
    I think you can browse your files in the cloud using the Cloud Explorer in VS. Worst case scenario you should be able to open Kudu from the Cloud Explorer (or the Azure Portal) and check the file/folder hierarchy you have there. Of course, eventually you should use some generic approach like @canton7 suggested above, but it is a good way to have a better understanding about what you have. This [link](https://learn.microsoft.com/en-us/visualstudio/azure/vs-azure-tools-resources-managing-with-cloud-explorer?view=vs-2019#view-and-navigate-resources-in-cloud-explorer) might help. – Akos Jun 09 '20 at 09:35
  • Thanks to your suggestions I was able to find my problem: some of my files was not marked as 'Copy to output directory'. Many thanks. – Bronzato Jun 09 '20 at 12:37
  • 1
    If my solution is useful for this problem, I hope you can adopt it and help more users.Tks! – Jason Pan Jun 11 '20 at 01:18

1 Answers1

0

The reason for this problem is that the TextFile.txt file was not included at the time of publication.

Akos said is right. I am modifying the .csproj file to send out my answer. Can better help other users of the forum.

You can paste code in your .csproj file.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <ResolvedFileToPublish Include="TextFile.txt">
      <RelativePath>TextFile.txt</RelativePath>
    </ResolvedFileToPublish>
  </ItemGroup>
</Project>

Then you can deploy your app. You can find TextFile.txt under D:\home\site\wwwroot>.

enter image description here

Jason Pan
  • 15,263
  • 1
  • 14
  • 29