c# wcf file and folder browser-Collection of common programming errors
Soner GönülI have a windows service that host a wcf service to allow remot file and folder browsing. The windows service runs under the local system account.
When browsing the
c:\
drive the service reports over 2800 files in that folder. i have single stepped through the code and it does indeed report >2800 files.How can this be correct?
C# Code
//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; } }
Noctisthe path i was passing in was c: what i should be passing in is c:\\
C# Code
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; } }
thanks Damo