2016-05-05 69 views

回答

0

你可以嘗試這樣的事:

try { 
    String filePath = @"yourfolder\Filename.docx"; 
    String newfilePath = @"yourNweFolder\NewFileName" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".docx"; 
    File.Copy(filePath, newfilePath, false); 
} catch(Exception ex) { 
    //Do stuff 
} 

或者使用下面的代碼來獲取文件路徑

String fileName = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath 
        + "YourNewFolderName", "YourNewFileName" 
        + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc"); 
+0

謝謝配合!我做了類似的工作: string sourceFile = Server.MapPath(「Templates/mytemplate.docx」); string destFile = Server.MapPath(「NewDocuments/NovoDocumento_」+ title +「.docx」); System.IO.File.Copy(sourceFile,destFile,true); –

相關問題