给定的路径不支持C#

问题描述:

我有一个奇怪的问题我有一个应用程序,扫描目录并获取文件列表。它通过阅读并做一些事情来处理每个文件。它在开发计算机中工作正常,但是当我将它部署到客户端时,它给我提供了错误。这里是代码给定的路径不支持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' –

我想知道这是否可能与file.fullname有关,改变文件路径字符串并给出不可接受的结果。您可以使用processThisIMFile(Path.GetFullPath(file))进行疑难解答吗?另外,在processthisim文件之前使用messagebox.show(file.FullName)以确认结果如预期。