//創建文件夾路徑
string path = "http://Files//";
//判斷文件夾是否存在
if (!Directory.Exists(path)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/" + path)); //不存在,則創建。 }
//原模版
string oldfile="http://oldfile//模版.xls";
//復制后的模版
string newfile=System.AppDomain.CurrentDomain.BaseDirectory + path +"新模版.xls";
//判斷文件是否存在
if(File.Exists(newfile))
{
File.Delete(newfile); //刪除
}
//復制文件
File.Copy(HttpContext.Current.Server.MapPath("~/" + oldfile),newfile);
//對模版進行操作,寫入內容,然后導出Excel
.......................................
//導出成功后,刪除文件夾下的模版文件,以防止日后文件逐漸增多,對網站帶來不必要的影響。
//判斷文件是否存在
if(File.Exists(newfile))
{
File.Delete(newfile); //刪除
}
新聞熱點
疑難解答