簡體   English   中英

從文件夾獲取特定文件

[英]Get a specific file from folder

我有這個文件夾,我想從中獲取一個特定的文件,鑒於那里可能有多個文件,我該怎么辦。

我嘗試使用StartsWith但無法這樣做,有什么辦法可以做到?

該文件位於CustomerWorkSheet文件夾中,其名稱以“ customer id字段值開頭。 如果我具有以下路徑,應該使用什么: .../uploads/attachments/CustomerWorkSheet/**File Name Here**

IWordDocument doc = new WordDocument();
doc.Open(
      System.Web.HttpContext.Current.Server.MapPath
             ("~/Content/uploads/attachments/CustomerWorkSheet/"), 
      FormatType.Doc);

我需要這樣的東西

if(file.StartsWith(customerId))

但無法獲取文件

var directoryPath = System.Web.HttpContext.Current.Server.MapPath("~/Content/uploads/attachments/CustomerWorkSheet");
var file = Directory.EnumerateFiles(directoryPath).SingleOrDefault(f => f.Contains("CustomerWorkSheet/" + myCustomerId));
if(file != null){
  IWordDocument doc = new WordDocument();
  doc.open(file, FormatType.Doc);
}

根據您的評論,您正在尋找:

var filename = myDirectoryFiles.SingleOrDefault(f => f.Contains("CustomerWorkSheet/" + myCustomerId + "."));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM