保存文件到当前项目中 适用于项目中的文件上传

  
FileUpload1    

string f = System.AppDomain.CurrentDomain.BaseDirectory.ToString();//获取项目当前目录,也可以使配置文件中自己配置的地址
//保存地址string savePath = "\files\网站发布\" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + "\" + fbwzID + "\" + mTpxx.TPBT + ".html";//虚拟路径string FilePath = f + savePath;//绝对物理路径(文件真正保存的位置)if (!Directory.Exists(Path.GetDirectoryName(FilePath)))
  {
 //创建路径
 Directory.CreateDirectory(Path.GetDirectoryName(FilePath));
 }

 //创建HTML文件,写入HTML,全路径带扩展名
 File.Delete(FilePath);

//保存方法(两种):  

//直接保存字符成文件

   File.AppendAllText(FilePath, strHtml.ToString(), Encoding.Default);

//上传附件的保存方法:

      FileUpload1.SaveAs(path + fileinfo.Name);
原文地址:https://www.cnblogs.com/zecVip/p/4429167.html