Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DownloadFileInfoTaskAsync for WebClient #18

Open
adamfisher opened this issue Dec 20, 2018 · 2 comments
Open

Add DownloadFileInfoTaskAsync for WebClient #18

adamfisher opened this issue Dec 20, 2018 · 2 comments
Assignees

Comments

@adamfisher
Copy link
Contributor

The WebClient class defines DownloadFileTaskAsync as:

public Task DownloadFileTaskAsync(string address, string fileName);

Which is nice but it does not return a reference to the file that was downloaded. An extension method like the following would be helpful (possibly good to do for the non-async version as well):

/// <summary>
/// Downloads the specified resource to a local file as an asynchronous operation using a task object.
/// </summary>
/// <param name="webClient">The web client.</param>
/// <param name="address">The URI of the resource to download.</param>
/// <param name="fileName">The name of the file to be placed on the local computer.</param>
/// <returns>
/// Returns <see cref="System.Threading.Tasks.Task"></see>.
/// The task object representing the asynchronous operation.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="address">address</paramref> parameter is null.
/// -or-
/// The <paramref name="fileName">fileName</paramref> parameter is null.</exception>
/// <exception cref="T:System.Net.WebException">The URI formed by combining <see cref="System.Net.WebClient.BaseAddress"></see> and <paramref name="address">address</paramref> is invalid.
/// -or-
/// An error occurred while downloading the resource.</exception>
/// <exception cref="T:System.InvalidOperationException">The local file specified by <paramref name="fileName">fileName</paramref> is in use by another thread.</exception>
public static Task<FileInfo> DownloadFileInfoTaskAsync(this WebClient webClient, string address, string fileName)
{
	return webClient.DownloadFileTaskAsync(address, fileName)
		.ContinueWith(task => new FileInfo(fileName));
}
@JonathanMagnan JonathanMagnan self-assigned this Dec 21, 2018
@JonathanMagnan
Copy link
Member

Hello @adamfisher ,

Thank you for reporting,

We will look at it according to the other issue you created.

Best Regards,

Jonathan

@adamfisher
Copy link
Contributor Author

@JonathanMagnan Any movement on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants