c#wcf文件和文件夹浏览器

我有一个Windows服务主机的WCF服务,以允许远程文件和文件夹浏览。 Windows服务在本地系统帐户下运行。

浏览c:\驱动器时,该服务报告该文件夹中的2800个文件。 我单步穿过代码,它确实报告> 2800个文件。

这怎么可能是正确的?

C#代码

  //Files Manager public ReturnClass FindSubFiles(String Folder_To_Search, String User, String SessionId) { ReturnClass myReturnClass = new ReturnClass(-1, String.Empty, String.Empty, null, null, null, null); try { Logging.Write_To_Log_File("Entry", MethodBase.GetCurrentMethod().Name, "", "", "", "", User, SessionId, 1); string[] filePaths = Directory.GetFiles(Folder_To_Search); int count = 0; foreach (string Folder in filePaths) { filePaths[count] = Path.GetFileName(filePaths[count]); count++; } myReturnClass.ErrorCode = 1; myReturnClass.FilePaths = filePaths; Logging.Write_To_Log_File("Exit", MethodBase.GetCurrentMethod().Name, "", "", "", "", User, SessionId, 1); return myReturnClass; } catch (Exception ex) { Logging.Write_To_Log_File("Error", MethodBase.GetCurrentMethod().Name, "", "", ex.ToString(), "", User, SessionId, 2); myReturnClass.ErrorCode = -1; myReturnClass.ErrorMessage = ex.ToString(); return myReturnClass; } } 

将其粘贴到一个C#控制台应用程序,看看它吐出了什么。 您必须在您的folder_To_Search中传递意想不到的内容,或者在c:\中包含比您想象的更多的文件。

 var Folder_To_Search = @"c:\"; string[] filePaths = Directory.GetFiles(Folder_To_Search); int count = 0; foreach (string Folder in filePaths) { filePaths[count] = Path.GetFileName(filePaths[count]); count++; } Console.WriteLine(count); Console.ReadKey(); 

我传递的路径是c:我应该传递的是c:\\

C#代码

 public ReturnClass FindSubFiles(String Folder_To_Search , String User, String SessionId ) { ReturnClass myReturnClass = new ReturnClass(-1, String.Empty, String.Empty, null, null, null, null); try { Logging.Write_To_Log_File("Entry", MethodBase.GetCurrentMethod().Name, "", "", "", "", User, SessionId, 1); string[] filePaths = Directory.GetFiles(Folder_To_Search + "\\"); int count = 0; foreach (string Folder in filePaths) { filePaths[count] = Path.GetFileName(filePaths[count]); count++; } myReturnClass.ErrorCode = 1; myReturnClass.FilePaths = filePaths; Logging.Write_To_Log_File("Exit", MethodBase.GetCurrentMethod().Name, "", "", "", "", User, SessionId, 1); return myReturnClass; } catch (Exception ex) { Logging.Write_To_Log_File("Error", MethodBase.GetCurrentMethod().Name, "", "", ex.ToString(), "", User, SessionId, 2); myReturnClass.ErrorCode = -1; myReturnClass.ErrorMessage = ex.ToString(); return myReturnClass; } } 

谢谢达摩