C# downloading files from the Internet

Posted: September 29, 2014 in C#
Tags:

Forma bir adet TextBox ve Button ve SaveFİleDialog ekledik. TextBox’a url adresi girildiğinde dosya download işlemini gerçekleştirecek.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
byte[] buffer = webClient.DownloadData(textBox1.Text);
if (DialogResult.OK == saveFileDialog1.ShowDialog())
{
FileStream bayram = new FileStream(saveFileDialog1.FileName, FileMode.Create);
bayram.Write(buffer, 0, buffer.Length);
bayram.Close();
}
}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}
}
}

21

22

23

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s