Reputation: 2748
I 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;
}
}
Upvotes: 2
Views: 1175
Reputation: 2748
the 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
Upvotes: 1
Reputation: 4999
Paste this into a C# Console Application and see what it spits out. You must be passing in something unexpected in your folder_To_Search, or have more files than you think in 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();
Upvotes: 1