using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Web.HttpContext.Current.Server.MapPath;    namespace 追加文件删除文件
{
    class Program
    {
        static void Main(string[] args)
        {
           // C#追加文件 
            StreamWriter sw = File.AppendText(Server.MapPath(".") + "\\myText.txt");    //这里有问题???
            sw.WriteLine("追逐理想"); 
            sw.WriteLine("kzlll"); 
            sw.WriteLine(".NET笔记"); 
            sw.Flush(); 
            sw.Close();         }
    }
}麻烦大家给我看看啊,哪里有问题,命名空间还是server.mappath那里有问题,谢谢了

解决方案 »

  1.   

    你这个应该是一个 命令行模式的,在这个下面是无法使用 Server.MapPath
    如果你要取得当前程序执行的目录,请使用 AppDomain.CurrentDomain.BaseDirectory属性
      

  2.   

    Server.MapPath这个之有在webform里面才有
      

  3.   


    using System; 
    using System.IO; 
    using System.Collections.Generic; 
    using System.Text; 
    using System.Web.HttpContext.Current.Server.MapPath;  namespace 追加文件删除文件 

        class Program 
        { 
            static void Main(string[] args) 
            { 
              // C#追加文件 
                StreamWriter sw = File.AppendText(Application.StartupPath+ "\\myText.txt");    //这里有问题??? 
                sw.WriteLine("追逐理想"); 
                sw.WriteLine("kzlll"); 
                sw.WriteLine(".NET笔记"); 
                sw.Flush(); 
                sw.Close();         } 
        } 
      

  4.   

    可执行文件目录的话加Application.StartupPath+"\\myText.txt");