In a C# 2008 windows application, I planning on locating files that I need to find by utilizing the following code:
var RFiles = from path in Directory.EnumerateFiles(filesaveLocation, "*.*",
SearchOption.AllDirectories)
let extension = Path.GetExtension(path)
where extension == ".pdf" || extension == ".xlsx" || extension == ".xls"
select path;
However once I find each selected file, I need to know the exact location of where each specified file was located. I need to be able to store the exact directory structure location in a sql server 2008 r2 database.
Basically the code statement would be similar to tell me exactly where each seelcted file is located at.
Thus can you me in code and/or explain to me how to accomplish my goal?
C# location of file in ditectory structure
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Mar 7, 2013, 4:30 AM EST
VulpesRank #55 · 29.2K reputationPosted Mar 7, 2013, 5:04 AM EST
See the docs for Directory.EnumerateFiles and in particular the Return Value section:
http://msdn.microsoft.com/en-us/library/dd383571.aspx
If you want to extract the path of the directory in which the file resides, you can use
string dirPath = Path.GetDirectoryName(path);