using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace webload
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private WebClient client;
//connect
private void button1_Click(object sender, EventArgs e)
{
string url = textBox1.Text;
try
{
WebRequest req = WebRequest.Create(url);
textBox1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true;
}
catch (WebException exp)
{
MessageBox.Show(exp.Message, "error");
}
}
//download
private void button2_Click(object sender, EventArgs e)
{
textBox1.Enabled = true;
button2.Enabled = false;
button3.Enabled = false;
listBox1.Items.Clear();
client = new WebClient();
client.DownloadFile(textBox1.Text,"web.aspx");
Stream strm = client.OpenRead(textBox1.Text);
StreamReader sr = new StreamReader(strm);
string line;
do
{
line = sr.ReadLine();
if (line != null) { listBox1.Items.Add(line); }
}
while (line != null);
strm.Close();
}
//upload
private void button3_Click(object sender, EventArgs e)
{
textBox1.Enabled = true;
button2.Enabled = false;
button3.Enabled = false;
listBox1.Items.Clear();
openFileDialog1.Filter = "html(*.html)|*.html|txt(*.txt)|*.txt|all files(*.*)|*.*";
openFileDialog1.Title = "browse file to upload";
string filepath = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
filepath = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
client = new WebClient();
client.UploadFile(textBox1.Text, filepath);
}
}
}
}
No comments:
Post a Comment