
#Simplefile downloader code
The code needed to then pause, resume or cancel the downloads couldn't be simpler: Note: The example code in this article is for a C# WPF application, and will be slightly different for a C# forms application. If the line is not empty, assume it's a valid URL // and add it to the files list // Note: You could check if the URL is valid before adding it, // and probably should do this is a real applicationĭ( new FileDownloader.FileInfo(trimmedLine)) String trimmedLine = line.Trim( ' ', ' \r') Get the contents of the rich text box string rtbContents = new TextRange(,įoreach ( string line in rtbContents.Split( ' \n')) Clear the current list of files (in case it's not the first download) Set the path to the local directory where the files will be downloaded toĭownloader.LocalDirectory = openFolderDialog.SelectedPath A simple implementation of setting the directory path, // adding files from a textbox and starting the download private void btnStart_Click( object sender, RoutedEventArgs e)

You'll also need to set the local directory to which you want to download. The first thing you need to do when using this class is (logically) create a new instance, and then add the files you want to download. Once you added the class to your project, you should be able to access it via the project's namespace. Another difference with the original VB.NET implementation is that this code uses a WPF demo application, and not a Windows Forms based one. Check the VB.NET Background File Downloader article for the original code. I originally wrote it in VB.NET, but have now created a C# implementation.
#Simplefile downloader how to
I started working on this class after someone on a programming help forum asked how to best download files in the background. On top of this, you can cancel downloading, pause it, and of course, also resume. Otherwise you may experience file access permissions issues (log file will not be created/updated).Īll files for download must be placed in the download folder you specified in the script settings.This class enables you to easily download multiple files in the background (via a separate thread), and will provide information about the amount of downloaded data, the percentage of completion, and the download speed. Make sure you set write permissions on the folder where downloads log is saved if you turned downloads log feature on. Use following syntax for downloads: download.php?f=FileName.
#Simplefile downloader update
Update download.php with your desired settings for base downloads folder, downloads log file name, allowed file types.automatic mime type detection (if Mimetype or Fileinfo extension installed on the server).Log file includes: IP, date/time, filename.

