Telecharger des fichiers, par le protocole http

Description

bonjour, voila un pt outil pour telecharger des fichiers a partir d'un serveur..

Source / Exemple :


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;

namespace Download
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label urlL;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox url;
		private System.Windows.Forms.SaveFileDialog saveFile;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox fileLocation;
		private System.Windows.Forms.Button download;
		private System.Windows.Forms.TextBox FileName;
		private System.Windows.Forms.Button btnExit;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.download = new System.Windows.Forms.Button();
			this.urlL = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.url = new System.Windows.Forms.TextBox();
			this.saveFile = new System.Windows.Forms.SaveFileDialog();
			this.FileName = new System.Windows.Forms.TextBox();
			this.button2 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.fileLocation = new System.Windows.Forms.TextBox();
			this.btnExit = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// download
			// 
			this.download.Enabled = false;
			this.download.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.download.Location = new System.Drawing.Point(144, 112);
			this.download.Name = "download";
			this.download.Size = new System.Drawing.Size(152, 23);
			this.download.TabIndex = 0;
			this.download.Text = "Download File !!";
			this.download.Click += new System.EventHandler(this.download_Click);
			// 
			// urlL
			// 
			this.urlL.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.urlL.Location = new System.Drawing.Point(8, 10);
			this.urlL.Name = "urlL";
			this.urlL.Size = new System.Drawing.Size(40, 16);
			this.urlL.TabIndex = 1;
			this.urlL.Text = "URL :";
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(8, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 2;
			this.label2.Text = "File Name :";
			// 
			// url
			// 
			this.url.Location = new System.Drawing.Point(72, 8);
			this.url.Name = "url";
			this.url.Size = new System.Drawing.Size(328, 20);
			this.url.TabIndex = 3;
			this.url.Text = "http://";
			// 
			// saveFile
			// 
			this.saveFile.FileName = "crack_xp";
			this.saveFile.Filter = "All Files | *.*";
			// 
			// FileName
			// 
			this.FileName.Location = new System.Drawing.Point(72, 46);
			this.FileName.Name = "FileName";
			this.FileName.Size = new System.Drawing.Size(184, 20);
			this.FileName.TabIndex = 4;
			this.FileName.Text = "(The Name Of the file to download it!)";
			// 
			// button2
			// 
			this.button2.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button2.Location = new System.Drawing.Point(328, 80);
			this.button2.Name = "button2";
			this.button2.TabIndex = 5;
			this.button2.Text = "Browse";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(8, 83);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 6;
			this.label1.Text = "Save As :";
			// 
			// fileLocation
			// 
			this.fileLocation.Location = new System.Drawing.Point(72, 81);
			this.fileLocation.Name = "fileLocation";
			this.fileLocation.Size = new System.Drawing.Size(248, 20);
			this.fileLocation.TabIndex = 8;
			this.fileLocation.Text = "";
			// 
			// btnExit
			// 
			this.btnExit.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnExit.Location = new System.Drawing.Point(328, 112);
			this.btnExit.Name = "btnExit";
			this.btnExit.TabIndex = 9;
			this.btnExit.Text = "EXIT";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(410, 144);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.fileLocation);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.FileName);
			this.Controls.Add(this.url);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.urlL);
			this.Controls.Add(this.download);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "Form1";
			this.Text = "Download\'s Tool (By Crack_XP)";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void download_Click(object sender, System.EventArgs e) {
			string remoteUri = url.Text;
			string fileName = FileName.Text, myStringWebResource = null;
			// Create a new WebClient instance.
			WebClient myWebClient = new WebClient();
			// Concatenate the domain with the Web resource filename.
			myStringWebResource = remoteUri + fileName;
			MessageBox.Show("Downloading File \"{0}\" from \"{1}\" .......\n\n"+fileName+myStringWebResource);
			// Download the Web resource and save it into the current filesystem folder.
			myWebClient.DownloadFile(myStringWebResource,fileLocation.Text);        
			MessageBox.Show("Successfully Downloaded File!!");
			MessageBox.Show("Downloaded file saved in the following file system folder:\n\t" + fileLocation.Text);			

		}

		private void button2_Click(object sender, System.EventArgs e) {
			if (saveFile.ShowDialog()==DialogResult.OK){
				fileLocation.Text=saveFile.FileName;
				download.Enabled=true;
				}
				
				
		}

		private void btnExit_Click(object sender, System.EventArgs e) {
			Application.Exit();
		}
	}
}

Conclusion :


voir le zip, et bien respecter le format des (url/repertoir_From/),
nom des fichiers(file.extention)et en fin le l'emlacement et le nom.extention

VOIR LA CAPTURE POUR MIEUX COMPRENDRE

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.