I needed to check whether a file exists inside a folder in document library, so I wrote the following code:
SPList list = web.Lists["DOC1"];
string fileName = "Sample.docx";
if (!list.RootFolder.Files[string.Format("{0}/{1}", list.RootFolder.Url, fileName)].Exists)
{
// Code Implementation
}
It turned out that the proper way of doing this is to use the GetFile method of SPWeb object like this:
SPFile file = web.GetFile(string.Format("{0}/{1}", list.RootFolder.Url, fileName));
if (file.Exists)
{
// Code Implementation
}