2016-11-30 112 views
0

我有一個奇怪的問題我有一個應用程序,掃描目錄並獲取文件列表。它通過閱讀並做一些事情來處理每個文件。它在開發計算機中工作正常,但是當我將它部署到客戶端時,它給我提供了錯誤。這裏是代碼給定的路徑不支持C#

public void ProcessIMFiles() 
    { 
     DirectoryInfo di = new DirectoryInfo(Globals.ITMDIR); 
     FileInfo[] Files = di.GetFiles("*.txt");    
     foreach(FileInfo file in Files) 
     { 
      try 
      { 
       processThisIMFile(file.FullName); 
       movefile(file.FullName); 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show("error : " + ex.Message); 
      } 
     } 
    } 

錯誤發生在processThisIMFile(file.FullName)調用請參閱下面。 Globals.ITMDIR是一個有效的路徑。

private void processThisIMFile(string FileName) 
    { 
     string[] Fields = null; 
     setconnection(); 
     DataTable dt = null; 
     try 
     { 
      string[] Lines = System.IO.File.ReadAllLines(FileName); 

      foreach (string line in Lines) 
      { 
       Fields = line.Split(Globals.delimiter); 
       if (Fields.Length == 7) 
       { 
        //stuff happens here 
       } 
     }//Try 
     catch (Exception e) 
     { 
      if (Interactive) 
      { 
       MessageBox.Show("Error in the Path: ->" + FileName); 
       writeToLog(true, "error opening file " + FileName); 
      } 
     } 
    }//end of processThisItemFile 

錯誤發生在 「字符串[]行= System.IO.File.ReadAllLines(文件名)」 線。 FileName來自di.GetFiles(「*。txt」);當我展示實際路徑時,它對我來說看起來很好。我曾嘗試使用UNC路徑和C:\ tmp \ filename.txt或\\ server \ tmp \ filename.txt中的驅動器盤符路徑在deplopyment計算機中失敗,並顯示「給定的路徑不受支持」,但它工作正常在開發機器中。

這是怎麼回事?

+0

可能的重複http://stackoverflow.com/questions/7348768/the-given-paths-format-is-not-supported – MWS

+0

也許需要一些日誌。在'processThisIMFile'中記錄'FileName' –

回答

0

我想知道這是否可能與file.fullname有關,改變文件路徑字符串並給出不可接受的結果。您可以使用processThisIMFile(Path.GetFullPath(file))進行疑難解答嗎?另外,在processthisim文件之前使用messagebox.show(file.FullName)以確認結果如預期。

相關問題