运行文件服务器上文件夹,我可以从运行在其上的Web API应用程序将文件写入服务器计算机上的文件夹吗?...
Posted weixin_39890543
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运行文件服务器上文件夹,我可以从运行在其上的Web API应用程序将文件写入服务器计算机上的文件夹吗?...相关的知识,希望对你有一定的参考价值。
我在我的Web API应用程序中使用此代码写入CSV文件:
private void SaveToCSV(InventoryItem invItem, string dbContext)
string csvHeader = "id,pack_size,description,vendor_id,department,subdepartment,unit_cost,unit_list,open_qty,UPC_code,UPC_pack_size,vendor_item,crv_id";
int dbContextAsInt = 0;
int.TryParse(dbContext, out dbContextAsInt);
string csvFilename = string.Format("Platypus0.csv", dbContextAsInt);
string csv = string.Format("0,1,2,3,4,5,6,7,8,9,10,11,12", invItem.ID,
invItem.pksize, invItem.Description, invItem.vendor_id, invItem.dept, invItem.subdept, invItem.UnitCost,
invItem.UnitList, invItem.OpenQty, invItem.UPC, invItem.upc_pack_size, invItem.vendor_item, invItem.crv_id);
string existingContents;
using (StreamReader sr = new StreamReader(csvFilename))
existingContents = sr.ReadToEnd();
using (StreamWriter writetext = File.AppendText(csvFilename))
if (!existingContents.Contains(csvHeader))
writetext.WriteLine(csvHeader);
writetext.WriteLine(csv);
在开发机器上,默认情况下,csv文件保存为"C:\\ Program Files(x86)\\ IIS Express".为了准备将它部署到最终的休息/工作场所,我需要做些什么来保存文件,例如,到服务器的"Platypi"文件夹 - 什么特别的?我是否必须专门设置某些文件夹柿子才能写入"Platypi".
这只是改变这条线的问题:
string csvFilename = string.Format("Platypus0.csv", dbContextAsInt);
......对此:
string csvFilename = string.Format(@"\\Platypi\\Platypus0.csv", dbContextAsInt);
?
以上是关于运行文件服务器上文件夹,我可以从运行在其上的Web API应用程序将文件写入服务器计算机上的文件夹吗?...的主要内容,如果未能解决你的问题,请参考以下文章