Understanding %temp%\.net Folder | WPF | Single File | Self Contained | WebView2

Theiss, Daniel 0 Reputation points
2025-03-28T09:27:04.87+00:00

When developing a single file self-contained WPF application using .NET 8 that uses the WebView2 component, a folder is created under %temp%\.net while the application is running.

What is the purpose of this folder, when and how is it created, and is it possible or needed to clean up this folder when the application is closed?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,853 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hongrui Yu-MSFT 5,255 Reputation points Microsoft External Staff
    2025-03-31T03:01:16.54+00:00

    Hi, @Theiss, Daniel. Welcome to Microsoft Q&A. 

    Purpose

    WebView2 applications use the user data folder (UDF) to store browser data (such as cookies, permissions, and cached resources), which WebView2 could use to speed up the program.

    When and how to create

    The user data folder (UDF) is created for your WebView2 host app by the WebView2 control. The UDF is created in the default UDF location for the platform, or if your host app specifies a custom UDF location, the UDF is created in the custom UDF location. The UDF is created on startup of the WebView2 host app, if the UDF doesn't exist.

    Can or need to clean this folder

    If the folder currently takes up too much space, you could clear this folder. For example, clear the contents of a folder when it reaches a specified size.

            private async Task ClearAutofillData()
            {
                double cleanSize = 10;
                var userDataFolder = "The address of your UDF folder";
    
                DirectoryInfo dirInfo = new DirectoryInfo(userDataFolder);
                double folderSize = dirInfo.GetFiles("*", SearchOption.AllDirectories).Sum(file => file.Length) / (1024.0 * 1024.0);
    
                if (folderSize >= cleanSize )
                {
                    CoreWebView2Profile profile;
                    if (MyWebView2.CoreWebView2 != null)
                    {
                        profile = MyWebView2.CoreWebView2.Profile;
                        await profile.ClearBrowsingDataAsync();
                    }
                }
            }
    

    For a more detailed description of this folder, you could refer to the official documentation:

    1.https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/user-data-folder?tabs=dotnet#what-kind-of-data-is-stored-in-the-udf

    2.https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/clear-browsing-data?tabs=csharp


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Theiss, Daniel 0 Reputation points
    2025-04-01T06:33:39.4933333+00:00

    Hi, @Hongrui Yu-MSFT
    Sometimes it is enough to talk to someone to get new ideas of what to look for.

    I found the corresponding place in the Microsoft documentation: Single-File Deploykment | Native Libraries

    The folder %temp%\.net is needed because we are using native libraries (in our case the WebView2 component) in a single file deployment.

    This folder is used to extract the native libraries from the single executable and load them into memory.

    Many thanks for your support!

    0 comments No comments

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.