关于c#
如何上传?
[解决办法]
用FTP你方法多的很,你到msdn搜索一下!
[解决办法]
string url = "www.baidu.com";
Uri uri = new Uri(url);
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.Default, true);
string html = sr.ReadToEnd();
Encoding encoding = sr.CurrentEncoding; //Read() 与 Close() 间读取实际编码
sr.Close();
s.Close();
response.Close();
//保存成文件
StreamWriter sw = new StreamWriter(@"c:\baidu.htm", false, encoding);
sw.Write(html);
sw.Close();
[解决办法]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//浏览文件
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog MyDlg = new OpenFileDialog();
MyDlg.CheckFileExists = true;
if (MyDlg.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = MyDlg.FileName;
}
}
//上传文件
private void button2_Click(object sender, EventArgs e)
{
string MyFile = this.textBox1.Text;
if (!System.IO.File.Exists(MyFile))
{
MessageBox.Show(MyFile + "文件不存在!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
Microsoft.VisualBasic.Devices.Computer My =new Microsoft.VisualBasic.Devices.Computer();
My.Network.UploadFile(MyFile, this.textBox2.Text, "", "", true, 500);
MessageBox.Show(MyFile+"文件已经完成上传!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception MyEx)
{
MessageBox.Show(MyEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
//关闭程序
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
}
[解决办法]
csdn下载