I'm trying to download file with Xamarin, but receive an error massage:
An exception occurred during a WebClient request. I thing that the problem is with unhautorization, but I try to download imagen for multiple web, and have the same problem.
Code:
public void getFile() {
var pathToNewFolder = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/CodeScanner";
Directory.CreateDirectory(pathToNewFolder);
try
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
var folder = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/CodeScanner";
webClient.DownloadFileAsync(new Uri("http://www.dada-data.net/uploads/image/hausmann_abcd.jpg"), folder);
}
catch (Exception ex)
{
Console.WriteLine("ERROR:"+ ex.Message);
}
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
Console.WriteLine("ERROR: "+ e.Error.Message);
}
The error massage appears in Console.WriteLine( of Completed method.
Firts I create a folder and try to save file into it.
When this work, only need downloat file from local server.
thanks.