'WebClient downloads file that "sounds similar"
I'm in a situation where I know the systematics of filenames on a server, but not how many there are. Like abc_1.jpg, abc_2.jpg and so on. My idea was to just try downloading until a file does not exist – > if abc_1 exists, also try downloading 2 and so on. What actually happens is that instead of stopping the download as soon as a file does not exist it will keep downloading a file that sounds similar, in my case it will keep downloading abc_1.jpg when being asked for 2, 3, and so on. Any way to avoid that?
Here is the code
if (client == null)
{
client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(DownloadFileCompleted);
}
uri = "http://" + serverAdress + downloadTasks[0];
client.DownloadFileAsync(new System.Uri(uri, UriKind.Absolute), Application.persistentDataPath + "/" + newFileName);
downloadTasks.RemoveAt(0);
Solution 1:[1]
Well then, answering my own question. Was looking at the wrong end of the problem. It's not WebClient, it's the Apache Server:
"If the server receives a request for /some/dir/foo and /some/dir/foo does not exist, then the server reads the directory looking for all files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements, and returns that document."
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Heinenberg |
