First thing to clear up is this... a document library is not a folder and a folder is not a document library. A folder resides in a document library and the SPFolder class doesn't have the same methods as the SPDocumentLibrary class (unfortunately).
For example, you can get the last modified date of any file within an entire document library, but you can't get the last modified date of any file within a folder within that document library. I found this frustrating because that was exactly what I had to do.
Anyway, when you browse to a document library and click on a folder within that document library, you get a huge URL. One that looks something like http://intranet/site/subsite/DocLib/Forms/AllItems.aspx?RootFolder=%2fsite%2fsubsite%2fDocLib%2fFolderName&blah blah blah. Copy that link into a list with a URL field and sometimes you see this... http://intranet/site/subsite/DocLib/FolderName. Now, that's annoying when trying to figure out what the folder is in the URL that the user pastes.
So firstly, what you need to do is check if there is a value for RootFolder in the URL and if there is, convert it into the shortened version so you can more easily manipulate it.
if (strURL.Contains("RootFolder="))
{
// need to shorten it
int equalMark = strURL.IndexOf("=");
int ampersandMark = strURL.IndexOf("&");
string folderURL = SPEncode.UrlDecodeAsUrl(strURL.Substring((equalMark + 1), (ampersandMark - equalMark - 1)));
SPSite site = new SPSite(strURL);
strURL = site.Url + folderURL; // now the url is the link direct to the folder itself.
}
From this smaller URL, you can get the document library details (see here). Then as far as I know, you have to loop through all the folders in the document library to find the one you are after.
SPSite site = new SPSite(strURL);
SPWeb web = site.OpenWeb();
string[] explode = strURL.Replace(web.Url, "").Split(new char[] { '/' });
string splitURL = explode[1];
string splitFolderName = explode[2];
string docLibName = SPEncode.UrlDecodeAsUrl(splitURL); // (this is also the list name with the location we're after)
foreach (SPListItem folderListItem in web.Lists[docLibName].Folders)
{
if (folderListItem.Name == strFolderName) // compare
{
// then now we go through the items in this folder and see if there is anything new
foreach (SPFile file in folderListItem.Folder.Files)
{
// you can now go through each file in that folder
}
}
}
Note that web.Lists[docLibName].Folders is of type SPFolder already so you can manipulate the folder if you need to.