How to reference the C:\Users\Public directory programmatically in C#

前端 未结 6 910
日久生厌
日久生厌 2021-01-04 00:33

Is it safe to programmatically reference the public folder through:

Directory = System.Environment.GetEnvironmentVariable(\"public\")+\"MyCompanyName\" // et         


        
6条回答
  •  醉梦人生
    2021-01-04 01:06

    If you want a place to put application-specific data that can accessed by all users, use as a base:

    Environment.GetFolderPath(SpecialFolder.CommonApplicationData)
    

    Also, consider using Path.Combine to combine elements to form a new path:

    Path.Combine(
        Environment.GetFolderPath(SpecialFolder.CommonApplicationData),
        "MyCompanyName")
    

提交回复
热议问题