Created directory in c# is not visible in Windows Explorer!?

d. simic 41 Reputation points
2023-01-05T14:36:29.98+00:00

Hi

I have a very strange thing that I cannot explain.

I created a file and wanted to look at it right away in Explorer:

File.WriteAllText(JsonFile, JsonSerializer.Serialize(data));  

To my great surprise, it did not appear in Explorer. After some tests I found out that a created directory is not shown at all. If I execute the following code

        string dir = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);  
        dir = Path.Combine(dir, "Test2");  
        Directory.CreateDirectory(dir);  

then a directory is created but not displayed in Windows Explorer:

276553-image.png

The code tells me that the directory exists but I cannot see the directory in Windows Explorer.

276520-image.png

How is this possible? "Hidden files" is activated in explorer! What am I missing here?

I use the following:

  • VS Community 2022 Version 17.4.2
  • Programme in NET MAUI (C#) , with NET 7
  • Windows 10 Pro (licensed)
  • Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz , 16 GB RAM

Thanks

EDIT

But if I try it in the public folder, it works. The created folder is also visible in Windows Explorer!

Does anyone know this phenomenon?

276555-image.png

Windows development Windows App SDK
Developer technologies .NET .NET MAUI
Windows for business Windows Client for IT Pros User experience Other
Developer technologies C#
{count} votes

Accepted answer
  1. Rob Caplan - MSFT 6,032 Reputation points Microsoft Employee Moderator
    2023-01-05T18:29:44.283+00:00

    The key here is that you have a packaged (MSIX) WinUI app. That the app also uses MAUI and .Net isn't directly relevant to this behaviour, except that by default MAUI for Windows creates packaged apps.

    Packaged apps virtualize the AppData directory. See AppData operations on OSes earlier than Windows 10, version 1903 in the Understanding how packaged desktop apps run on Windows documentation. More details are behind the links, but here's the direct quote:

    All newly created files and folders in the user's AppData folder (for example, C:\Users\<user_name>\AppData) are written to a private per-user, per-app location; but merged at runtime to appear in the real AppData location.

    You should be able to use ProcMon to trace where the saved files actually end up. It's a great tool for chasing down file operations when they aren't where you thi-ink.

    5 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2023-01-05T16:16:26.433+00:00

    I cannot replicate your issue. As soon as the directory is created it shows up in Explorer. I suspect there is something going on with your roaming profile settings. This could be attributed to a network configuration perhaps but I wouldn't know where to look.

    Do you see the same behavior if you use LocalApplicationData instead of ApplicationData?

    If you switch to .NET 6 do you see the problem?

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.