扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:曹勇刚 来源:yesky 2007年11月17日
关键字: 软件
图 3 |
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; namespace DownLoadFile { /// /// Form1 is a Client For FileServer to Download File through HTTP /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox2;//getfile input path private System.Windows.Forms.Panel panel3; private System.Windows.Forms.TextBox textBox3;//url of web service private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button1;//getfile private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1;//username private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox4;//password private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox4 = new System.Windows.Forms.TextBox(); this.panel3 = new System.Windows.Forms.Panel(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.panel3.SuspendLayout(); this.SuspendLayout(); this.textBox2.Location = new System.Drawing.Point(8, 32); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(232, 21); this.textBox2.TabIndex = 1; this.textBox2.Text = "Please Input Path here"; this.textBox3.Dock = System.Windows.Forms.DockStyle.Fill; this.textBox3.Location = new System.Drawing.Point(56, 0); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(328, 21); this.textBox3.TabIndex = 2; this.textBox3.Text = "http://localhost/sei/test/useresdata/FileServer.asmx"; this.textBox1.Location = new System.Drawing.Point(80, 64); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(256, 21); this.textBox1.TabIndex = 5; this.textBox1.Text = "caomo"; this.textBox4.Location = new System.Drawing.Point(80, 96); this.textBox4.Name = "textBox4"; this.textBox4.PasswordChar = '*'; this.textBox4.Size = new System.Drawing.Size(256, 21); this.textBox4.TabIndex = 7; this.textBox4.Text = "password"; this.panel3.Controls.AddRange(new System.Windows.Forms.Control[] { this.textBox3, this.label2}); this.panel3.Dock = System.Windows.Forms.DockStyle.Top; this.panel3.Name = "panel3"; this.panel3.Size = new System.Drawing.Size(384, 24); this.panel3.TabIndex = 2; this.label2.Dock = System.Windows.Forms.DockStyle.Left; this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(56, 24); this.label2.TabIndex = 1; this.label2.Text = "Web服务:"; this.label1.Location = new System.Drawing.Point(8, 72); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(72, 16); this.label1.TabIndex = 4; this.label1.Text = "UserName:"; this.button1.Location = new System.Drawing.Point(256, 32); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(72, 24); this.button1.TabIndex = 3; this.button1.Text = "GetFile"; this.button1.Click += new System.EventHandler(this.button1_Click); this.label3.Location = new System.Drawing.Point(8, 96); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(64, 16); this.label3.TabIndex = 6; this.label3.Text = "Password"; this.saveFileDialog1.FileName = "doc1"; this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(384, 125); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.textBox4, this.label3, this.textBox1, this.label1, this.button1, this.panel3, this.textBox2}); this.Name = "Form1"; this.Text = "DownLoad File From Web Service"; this.panel3.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { localhost.Authentication auth=new localhost.Authentication(); auth.Username =textBox1.Text; auth.Password=textBox4.Text; localhost.FileServer fs=new localhost.FileServer(); fs.Url=textBox3.Text; fs.AuthenticationValue=auth; string s=null; try { s=fs.GetFile(textBox2.Text); if (s==null) MessageBox.Show("错误:请检查用户名和密码是否正确!","错误:"); else { byte[] btBuf = Convert.FromBase64String(s); int i=textBox2.Text.LastIndexOf("\\"); saveFileDialog1.FileName =textBox2.Text.Substring (i+1,textBox2.Text.Length-i-1); DialogResult drs=saveFileDialog1.ShowDialog(); if (drs==DialogResult.OK) { FileStream fstream = new FileStream(saveFileDialog1.FileName , FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter w = new BinaryWriter(fstream); w.Write (btBuf); w.Flush(); fstream.Close(); } } } catch { MessageBox.Show("错误:请检查网络是否连通或网络地址是否正确。","错误:"); } } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者