Can I write a file to a folder on a server machine from a Web API app running on it?

眉间皱痕 提交于 2019-12-03 12:24:25

In the case of the IIS folder the application has rights to write in there. I suggest to write files to the App_Data folder.

When you want to save files outside the IIS application folder you have to give the service account of the IIS application pool (I think it by default is NETWORKSERVICE) the appropriate rights on that folder.

As requested by B. Clay Shannon my implementation:

string fullSavePath = HttpContext.Current.Server.MapPath(string.Format("~/App_Data/Platypus{0}.csv", dbContextAsInt));

Thanks to Patrick Hofman; this is the exact code I am using, and it is saved to the project's App_Data folder:

public static string appDataFolder = HttpContext.Current.Server.MapPath("~/App_Data/");
. . .
string csvFilename = string.Format("Platypus{0}.csv", dbContextAsInt);
string fullSavePath = string.Format("{0}{1}", appDataFolder, csvFilename);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!