C# getting the path of %AppData%

后端 未结 10 2249
无人共我
无人共我 2020-11-22 13:50

C# 2008 SP1

I am using the code below:

dt.ReadXml(\"%AppData%\\\\DateLinks.xml\");

However, I am getting an exception that points t

10条回答
  •  迷失自我
    2020-11-22 14:34

    The path is different if you're talking ASP.NET.

    I couldn't find any of the 'SpecialFolder' values that pointed to /App_Data for ASP.NET.

    Instead you need to do this:

     HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data")  
    

    (Note: You don't need the 'Current' property in an MVC Controller)

    If theres another more 'abstract' way to get to App_Data would love to hear how.

提交回复
热议问题