C# 如何将文件写入本地文档库
我正在使用streamwriter写入文件,但是新写入文件的位置位于项目文件夹中的某个文件夹中,但我希望该位置位于计算机的文档库中。im使用的是mvc应用程序,而不是控制台应用程序 任何帮助都将不胜感激 多谢各位C# 如何将文件写入本地文档库,c#,asp.net-mvc,streamwriter,C#,Asp.net Mvc,Streamwriter,我正在使用streamwriter写入文件,但是新写入文件的位置位于项目文件夹中的某个文件夹中,但我希望该位置位于计算机的文档库中。im使用的是mvc应用程序,而不是控制台应用程序 任何帮助都将不胜感激 多谢各位 using (var File = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/OutputFileTest.csv"), false)) // true for appending the fil
using (var File = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/OutputFileTest.csv"), false)) // true for appending the file and false to overwrite the file
{
foreach (var item in outputFile)
{
File.WriteLine(item);
}
}
从MSDN:
// Sample for the Environment.GetFolderPath method
using System;
class Sample
{
public static void Main()
{
Console.WriteLine();
Console.WriteLine("GetFolderPath: {0}",
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
}
}
/*
This example produces the following results:
*/
我想您正在寻找这个:使用(var File=newstreamwriter(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+“/OutputFileTest.csv”,false))//true用于追加文件,false用于覆盖文件{foreach(outputFile中的var项){File.WriteLine(项)}}在使用您的代码后,我得到一个错误“System Environment确实包含特殊文件夹的定义”可能是