Class DownloadFile
Downloads a file from a specific internet address to a stream.
public class DownloadFile : TaskBase, ITask
- Inheritance
-
DownloadFile
- Implements
- Inherited Members
- Extension Methods
Constructors
DownloadFile(Uri, Action<Stream>, long)
Creates a new download task.
public DownloadFile(Uri source, Action<Stream> callback, long bytesTotal = -1)
Parameters
source
UriThe URL the file is to be downloaded from.
callback
Action<Stream>Called with a stream providing the download content.
bytesTotal
longThe number of bytes the file to be downloaded is long. The file will be rejected if it does not have this length. -1 if the size is unknown.
DownloadFile(Uri, string, long)
Creates a new download task.
public DownloadFile(Uri source, string target, long bytesTotal = -1)
Parameters
source
UriThe URL the file is to be downloaded from.
target
stringThe local path to save the file to. A preexisting file will be overwritten.
bytesTotal
longThe number of bytes the file to be downloaded is long. The file will be rejected if it does not have this length. -1 if the size is unknown.
Properties
BytesMaximum
The maximum number of bytes to download.
public long BytesMaximum { get; set; }
Property Value
ContentStarted
Indicates whether the server has started sending content.
public bool ContentStarted { get; }
Property Value
Name
A name describing the task in human-readable form.
public override string Name { get; }
Property Value
NoCache
Set to true
to add a No-Cache header to the request for any intermediate proxy servers.
public bool NoCache { get; set; }
Property Value
Source
The URL the file is to be downloaded from.
public Uri Source { get; }
Property Value
Remarks
This value may change once Data has been reached, based on HTTP redirections.
UnitsByte
true
if UnitsProcessed and UnitsTotal are measured in bytes;
false
if they are measured in generic units.
protected override bool UnitsByte { get; }
Property Value
Methods
Execute()
The actual code to be executed.
protected override void Execute()
Remarks
State is automatically set to Started before calling this method, to Complete after a successful exit and to an appropriate error state in case on an exception. You can set additional TaskStates during execution.
Exceptions
- OperationCanceledException
The operation was canceled.
- IOException
The task ended with IOError.
- WebException
The task ended with WebError.