把指定的路径加在文件的前面,如:
string file="c:\\mydir\\myfile.txt";
StreamWriter sw= new StreamWriter(file);
sw.Write("你的内容");
sw.Close();

解决方案 »

  1.   

    Stream fs=File.OpenWrite(Server.MapPath("你的文件路径"));
    StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding("gb2312"));
    sw.Write("要写的内容");
    sw.Flush();
    sw.Close();
    fs.Close();
      

  2.   

    Stream stream = new FileStream(filepath,FileMode.OpenOrCreate);//filepath就是路径
    StreamWriter writer = new StreamWriter(stream,System.Text.Encoding.GetEncoding("GB2312"));
      writer.Write(cs);
      writer.Close();
      

  3.   

    FileInfo file = new FileInfo(path);
    file.Open(...
      

  4.   

    什么样的文件?如果是图形可以用Image1.Save参考生成Text文件的列子 public bool WriteLogFile( string _FilePath, string _FileContent )
    {
    try
    {
    System.IO.FileStream oFileStream;
    if ( ! System.IO.File.Exists( _FilePath ) )
    {
    oFileStream = new System.IO.FileStream( _FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite );
    }
    else
    {
    oFileStream = new System.IO.FileStream( _FilePath, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite );
    }
    System.IO.StreamWriter oStreamWriter = new System.IO.StreamWriter( oFileStream, System.Text.Encoding.Default );
    oStreamWriter.Write( _FileContent );
    oStreamWriter.WriteLine();
    oStreamWriter.Close();
    oFileStream.Close();
    return true;
    }
    catch( System.Exception ex )
    {
    System.Web.HttpContext.Current.Response.Write( ex.ToString() );
    return false;
    }
    }
      

  5.   

    是指工程编译后的文件?在“项目”中选“属性”可以在其中找到输出路径的设置
    默认的debug\bin