Hoping I explain this like I am thinking
I have a web app which has products, from a list of suppliers. e.g. www.example.com.au/Browse.aspx?SupplierID=XYZ displays products for XYZ suppliers only. This then goes to the details page www.example.com.au/Product.aspx?ProductID=123. This page displays a list of details for that product (gallery of images, product data sheets, i.e PDFs, etc).
Now, each supplier is given an ftp account, where he can upload their product information - ftp://resources.example.com.au, and this is accessible via resources.example.com.au/*. So, let's say supplier XYZ will have something like:
resources.example.com.au/XYZ/123.jpg <== main product image
resources.example.com.au/XYZ/123_a.jpg <== secondary image
resources.example.com.au/XYZ/123_b.jpg <== secondary image
resources.example.com.au/XYZ/123_c.jpg <== secondary image
(Due to application requirement, the web app sits on a different server, than the resources folder)
Now, to get the list of related product images, i have the following:
public List<string> GetFiles(string strDirectoryName, string strStartsWith)
{
List<string> files = new List<string>();
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFTPUrl + strDirectoryName));
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(strFtpUser, strFtpPassword);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
while (!reader.EndOfStream)
{
string filename = reader.ReadLine().ToString();
if (filename.Length > 4)
{
if (!string.IsNullOrEmpty(strStartsWith))
{
if (filename.StartsWith(strStartsWith, StringComparison.OrdinalIgnoreCase))
{
files.Add(filename);
}
}
}
}
response.Close();
responseStream.Close();
reader.Close();
return files;
}
Unfortunately, this function goes through all the files (which could be around 100,000's), and selects only the file i need.
My question: is there a better way to filter only the images i need, rather than going through the entire directory?
Or, perhaps another way to get these images?