2016-09-06 67 views
-1

我正在使用streamwriter編寫文件,但是新寫入文件的位置位於項目文件夾中的某個文件夾中,但我希望位置處於打開狀態計算機的文檔庫。即時通訊使用mvc應用程序而不是控制檯應用程序如何將文件寫入本地文檔庫

任何幫助將不勝感激。

謝謝

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); 
       } 
      } 
+0

我認爲你正在尋找這樣的:https://msdn.microsoft.com/en-us/library/system.environment .specialfolder(v = vs.110).aspx –

+0

using(var File = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+「/OutputFileTest.csv」,false))// true用於附加文件,false覆蓋文件 foreach(outputFile中的var item) { File.WriteLine(item); } } –

+0

使用您的代碼後我得到一個錯誤「系統環境確實包含特殊文件夾的定義」 – user5813072

回答

0

從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: 

    */ 
相關問題