I just refactored your code, it goes through your root dir and look for the sub dirs that you wanted and check for the files you wanted. If you want to change the sub dirs or add new sub dirs, you just need to edit the "SubDirNames" array.
private string SubDirNames = new string
private List<string> GetSubDirectoryPaths(DirectoryInfo rootDir)
List<string> subDirs = new List<string>();
foreach (string subDirName in SubDirNames)
DirectoryInfo dirs = rootDir.GetDirectories(subDirName);
if (dirs.Length > 0)
string path = Path.Combine(rootDir.FullName, subDirName);
logging.Error("The location " + path + " does not exist for documents. ");
private string GetFiles(string subDir)
return (from path in Directory.GetFiles(subDir)
let name = Path.GetFileName(path)
where name.EndsWith(".pdf") ||
string packageId = "";
DateTime myDateTime = DateTime.Now.AddMonths(-1);
string fromDate = "_" + myDateTime.ToString("MMM").ToUpper() + " _" + myDateTime.ToString("yyyy");
string rootDirPath = Path.Combine(ConfigurationSettings.AppSettings["tLocation"], fromDate);
DirectoryInfo rootDir = new DirectoryInfo(rootDirPath);
logging.Error("The location " + rootDirPath + " does not exist for documents. ");
List<string> subDirPaths = GetSubDirectoryPaths(rootDir);
foreach (string subDir in subDirPaths)
string RVWFiles = GetFiles(subDir);
if (RVWFiles.Length > 0)
foreach (string RFile in RVWFiles)
string orgnizationName = "";
string contactName = "";
string fileNameWithExtension = Path.GetFileName(RFile);
string fileName = Path.GetFileNameWithoutExtension(RFile);
string Original_location = subDir;
string names = fileName.Split('_');
orgnizationName = names.TrimEnd();
contactName = names.TrimStart();
string strOrgnizationName = orgnizationName;
string items = contactName.TrimEnd().Split(' ');
string surname = items[items.Length - 1];
//--here does the processing that is required--// you cannot return here, you are still in the loop!//return null;
} //closing bracket for foreach (String RFile in RFiles)
logging.Info("packageId: " + packageId + " the location " + subDir + " does not contain any documents. ");
catch (Exception e)
logging.Error("Error Processing --> " + e.Message);
logging.Error("************* Stack Trace *******************");
// throwing an exception on exception is pointless; either catch the exception and handle it safely or let the compiler to throw the exception.//throw new Exception(e.Message);return packageId;
There are few other things, I an not sure about your "PackageId" variable, this is empty at the moment; and why are you returning the packageId when error occurs and returning "null" when success?
Second, don't throw exception on exception, it is pointless, either handle the exception or let the compiler does what it does best.
Third, if i were you, I would move the processing part of the file into a separate method too for better readability.
I hope this helps.
Think! Don't write a line of code unless you absolutely need to.
The typical way to store a password securely is typically not to store it at all. I know this sounds backwards, but what normally happens is that you hash the password beforehand and you save that hashed version to the database, along with the salt that you used to create the hash. Then, when you want to compare, you retrieve the row and perform the same hash using the salt that you saved to the database.
Now, before you ask, I've given you every keyword in there that you need to do this.
I was brought up to respect my elders. I don't respect many people nowadays.
I am doing one sample project in c#. Its lik billing project. I created combobox column in datagridview. i added items to combobox if i select one item from combobox in one row tat item should not list in next row combo box. Is it possible if yes means suggest me please.
//http://www.codeproject.com/Messages/4513781/I-have-string-1999220-how-to-parse.aspxstring theDate = "19881205";
char dateLetters = theDate.ToCharArray();
int dateNumbers = new int[theDate.Length];
int sum = 0;
for (int ind = 0; ind < theDate.Length; ind++)
Console.WriteLine("Current Total: " + sum.ToString());
dateNumbers[ind] = int.Parse(dateLetters[ind].ToString());
Console.WriteLine("Adding: " + dateNumbers[ind].ToString());
sum += dateNumbers[ind];
Console.WriteLine("New Total: " + sum.ToString());
Console.WriteLine("The sum of the numbers is: " + sum.ToString());
Console.WriteLine("Press any key to close the demo...");