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

前端 未结 2 1330
失恋的感觉
失恋的感觉 2021-02-14 14:59

I have this code in my Web API app to write to a CSV file:

private void SaveToCSV(InventoryItem invItem, string dbContext)
{
    string csvHeader = \"id,pack_siz         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 15:35

    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));
    

提交回复
热议问题