天天看點

.net中activex的替代技術:winform control(一)

.net中activex的替代技術:winform control(一)

        我想做用 vc 做一 activex 控件對初始程式設計的人來說可能不是一件容易的事吧,在 .net 出現之後,有更簡單的技術來替代它,那就是 winform control ,它可以把做好的 winform control 直接嵌入到 IE 中,對于通路本地磁盤和系統資料庫的 winform control ,可能要重新設定安全政策。我們就拿多檔案上傳為例,進行講述。

(一)   做一winform control

上面的代碼中,公布了Uri和ServerFolder屬性:Uri指定上傳的url位址,ServerFolder指定存放的上傳檔案的檔案夾;這倆個屬性都是可讀可寫的,可以在網頁中通過javascript和使用者互動。到此為止,上傳的winform控件就完成了,非常簡單。(未完待續)

.net中activex的替代技術:winform control(一)

using  System;

.net中activex的替代技術:winform control(一)

using  System.Collections;

.net中activex的替代技術:winform control(一)

using  System.ComponentModel;

.net中activex的替代技術:winform control(一)

using  System.Drawing;

.net中activex的替代技術:winform control(一)

using  System.Data;

.net中activex的替代技術:winform control(一)

using  System.Windows.Forms;

.net中activex的替代技術:winform control(一)

using  System.Runtime.InteropServices;

.net中activex的替代技術:winform control(一)

using  System.Net;

.net中activex的替代技術:winform control(一)

using  System.IO;

.net中activex的替代技術:winform control(一)

namespace  MultiFileUpload

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

    /// <summary>

.net中activex的替代技術:winform control(一)

    /// UserControl1 的摘要說明。

.net中activex的替代技術:winform control(一)

    /// </summary>

.net中activex的替代技術:winform control(一)

    public class Demo : System.Windows.Forms.UserControl

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Panel panel1;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Label label1;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Splitter splitter1;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Panel panel2;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Button button1;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Splitter splitter2;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Button button2;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.OpenFileDialog openFileDialog1;

.net中activex的替代技術:winform control(一)

        public WebClient wc=new WebClient();

.net中activex的替代技術:winform control(一)

        private string filestr="";

.net中activex的替代技術:winform control(一)

        private string[] FileListArr;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Splitter splitter3;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.ProgressBar progressBar1;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Splitter splitter4;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.Panel panel3;

.net中activex的替代技術:winform control(一)

        private System.Windows.Forms.ListBox listBox1;

.net中activex的替代技術:winform control(一)

        private string uri="http://10.126.65.96/WebApplication2";//根據自己的情況設定

.net中activex的替代技術:winform control(一)

        private string serverfolder="usercontrols";//根據自己的情況設定

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        /// <summary>

.net中activex的替代技術:winform control(一)

        /// 必需的設計器變量。

.net中activex的替代技術:winform control(一)

        /// </summary>

.net中activex的替代技術:winform control(一)

        private System.ComponentModel.Container components = null;

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        public Demo()

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            // 該調用是 Windows.Forms 窗體設計器所必需的。

.net中activex的替代技術:winform control(一)

            InitializeComponent();

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

            // TODO: 在 InitComponent 調用後添加任何初始化

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        /// <summary>

.net中activex的替代技術:winform control(一)

        /// 清理所有正在使用的資源。

.net中activex的替代技術:winform control(一)

        /// </summary>

.net中activex的替代技術:winform control(一)

        protected override void Dispose( bool disposing )

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            if( disposing )

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

                if( components != null )

.net中activex的替代技術:winform control(一)

                    components.Dispose();

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

            base.Dispose( disposing );

.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        public string Uri

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            set

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            this.uri=value;

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

            get

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            return this.uri;

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)

        public string ServerFolder

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            set

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            this.serverfolder=value;

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

            get

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            return this.serverfolder;

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        元件設計器生成的代碼#region 元件設計器生成的代碼

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        /// <summary>

.net中activex的替代技術:winform control(一)

        /// 設計器支援所需的方法 - 不要使用代碼編輯器 

.net中activex的替代技術:winform control(一)

        /// 修改此方法的内容。

.net中activex的替代技術:winform control(一)

        /// </summary>

.net中activex的替代技術:winform control(一)

        private void InitializeComponent()

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Demo));

.net中activex的替代技術:winform control(一)

            this.panel1 = new System.Windows.Forms.Panel();

.net中activex的替代技術:winform control(一)

            this.splitter3 = new System.Windows.Forms.Splitter();

.net中activex的替代技術:winform control(一)

            this.panel2 = new System.Windows.Forms.Panel();

.net中activex的替代技術:winform control(一)

            this.button2 = new System.Windows.Forms.Button();

.net中activex的替代技術:winform control(一)

            this.splitter2 = new System.Windows.Forms.Splitter();

.net中activex的替代技術:winform control(一)

            this.button1 = new System.Windows.Forms.Button();

.net中activex的替代技術:winform control(一)

            this.splitter1 = new System.Windows.Forms.Splitter();

.net中activex的替代技術:winform control(一)

            this.label1 = new System.Windows.Forms.Label();

.net中activex的替代技術:winform control(一)

            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

.net中activex的替代技術:winform control(一)

            this.progressBar1 = new System.Windows.Forms.ProgressBar();

.net中activex的替代技術:winform control(一)

            this.splitter4 = new System.Windows.Forms.Splitter();

.net中activex的替代技術:winform control(一)

            this.panel3 = new System.Windows.Forms.Panel();

.net中activex的替代技術:winform control(一)

            this.listBox1 = new System.Windows.Forms.ListBox();

.net中activex的替代技術:winform control(一)

            this.panel1.SuspendLayout();

.net中activex的替代技術:winform control(一)

            this.panel2.SuspendLayout();

.net中activex的替代技術:winform control(一)

            this.panel3.SuspendLayout();

.net中activex的替代技術:winform control(一)

            this.SuspendLayout();

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // panel1

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));

.net中activex的替代技術:winform control(一)

            this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

.net中activex的替代技術:winform control(一)

            this.panel1.Controls.Add(this.panel3);

.net中activex的替代技術:winform control(一)

            this.panel1.Controls.Add(this.splitter4);

.net中activex的替代技術:winform control(一)

            this.panel1.Controls.Add(this.progressBar1);

.net中activex的替代技術:winform control(一)

            this.panel1.Controls.Add(this.splitter3);

.net中activex的替代技術:winform control(一)

            this.panel1.Controls.Add(this.panel2);

.net中activex的替代技術:winform control(一)

            this.panel1.Controls.Add(this.splitter1);

.net中activex的替代技術:winform control(一)

            this.panel1.Controls.Add(this.label1);

.net中activex的替代技術:winform control(一)

            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;

.net中activex的替代技術:winform control(一)

            this.panel1.Location = new System.Drawing.Point(0, 0);

.net中activex的替代技術:winform control(一)

            this.panel1.Name = "panel1";

.net中activex的替代技術:winform control(一)

            this.panel1.Size = new System.Drawing.Size(568, 376);

.net中activex的替代技術:winform control(一)

            this.panel1.TabIndex = 0;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // splitter3

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.splitter3.Dock = System.Windows.Forms.DockStyle.Top;

.net中activex的替代技術:winform control(一)

            this.splitter3.Location = new System.Drawing.Point(72, 43);

.net中activex的替代技術:winform control(一)

            this.splitter3.Name = "splitter3";

.net中activex的替代技術:winform control(一)

            this.splitter3.Size = new System.Drawing.Size(494, 3);

.net中activex的替代技術:winform control(一)

            this.splitter3.TabIndex = 4;

.net中activex的替代技術:winform control(一)

            this.splitter3.TabStop = false;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // panel2

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

.net中activex的替代技術:winform control(一)

            this.panel2.Controls.Add(this.button2);

.net中activex的替代技術:winform control(一)

            this.panel2.Controls.Add(this.splitter2);

.net中activex的替代技術:winform control(一)

            this.panel2.Controls.Add(this.button1);

.net中activex的替代技術:winform control(一)

            this.panel2.Dock = System.Windows.Forms.DockStyle.Left;

.net中activex的替代技術:winform control(一)

            this.panel2.Location = new System.Drawing.Point(0, 43);

.net中activex的替代技術:winform control(一)

            this.panel2.Name = "panel2";

.net中activex的替代技術:winform control(一)

            this.panel2.Size = new System.Drawing.Size(72, 331);

.net中activex的替代技術:winform control(一)

            this.panel2.TabIndex = 2;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // button2

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.button2.Dock = System.Windows.Forms.DockStyle.Fill;

.net中activex的替代技術:winform control(一)

            this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

.net中activex的替代技術:winform control(一)

            this.button2.Location = new System.Drawing.Point(0, 155);

.net中activex的替代技術:winform control(一)

            this.button2.Name = "button2";

.net中activex的替代技術:winform control(一)

            this.button2.Size = new System.Drawing.Size(70, 174);

.net中activex的替代技術:winform control(一)

            this.button2.TabIndex = 2;

.net中activex的替代技術:winform control(一)

            this.button2.Text = "上傳檔案";

.net中activex的替代技術:winform control(一)

            this.button2.Click += new System.EventHandler(this.button2_Click);

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // splitter2

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.splitter2.Dock = System.Windows.Forms.DockStyle.Top;

.net中activex的替代技術:winform control(一)

            this.splitter2.Location = new System.Drawing.Point(0, 152);

.net中activex的替代技術:winform control(一)

            this.splitter2.Name = "splitter2";

.net中activex的替代技術:winform control(一)

            this.splitter2.Size = new System.Drawing.Size(70, 3);

.net中activex的替代技術:winform control(一)

            this.splitter2.TabIndex = 1;

.net中activex的替代技術:winform control(一)

            this.splitter2.TabStop = false;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // button1

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.button1.Dock = System.Windows.Forms.DockStyle.Top;

.net中activex的替代技術:winform control(一)

            this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

.net中activex的替代技術:winform control(一)

            this.button1.Location = new System.Drawing.Point(0, 0);

.net中activex的替代技術:winform control(一)

            this.button1.Name = "button1";

.net中activex的替代技術:winform control(一)

            this.button1.Size = new System.Drawing.Size(70, 152);

.net中activex的替代技術:winform control(一)

            this.button1.TabIndex = 0;

.net中activex的替代技術:winform control(一)

            this.button1.Text = "選擇檔案";

.net中activex的替代技術:winform control(一)

            this.button1.Click += new System.EventHandler(this.button1_Click);

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // splitter1

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;

.net中activex的替代技術:winform control(一)

            this.splitter1.Location = new System.Drawing.Point(0, 40);

.net中activex的替代技術:winform control(一)

            this.splitter1.Name = "splitter1";

.net中activex的替代技術:winform control(一)

            this.splitter1.Size = new System.Drawing.Size(566, 3);

.net中activex的替代技術:winform control(一)

            this.splitter1.TabIndex = 1;

.net中activex的替代技術:winform control(一)

            this.splitter1.TabStop = false;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // label1

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

.net中activex的替代技術:winform control(一)

            this.label1.Dock = System.Windows.Forms.DockStyle.Top;

.net中activex的替代技術:winform control(一)

            this.label1.Location = new System.Drawing.Point(0, 0);

.net中activex的替代技術:winform control(一)

            this.label1.Name = "label1";

.net中activex的替代技術:winform control(一)

            this.label1.Size = new System.Drawing.Size(566, 40);

.net中activex的替代技術:winform control(一)

            this.label1.TabIndex = 0;

.net中activex的替代技術:winform control(一)

            this.label1.Text = "多檔案上傳";

.net中activex的替代技術:winform control(一)

            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // progressBar1

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.progressBar1.Dock = System.Windows.Forms.DockStyle.Bottom;

.net中activex的替代技術:winform control(一)

            this.progressBar1.Location = new System.Drawing.Point(72, 351);

.net中activex的替代技術:winform control(一)

            this.progressBar1.Name = "progressBar1";

.net中activex的替代技術:winform control(一)

            this.progressBar1.Size = new System.Drawing.Size(494, 23);

.net中activex的替代技術:winform control(一)

            this.progressBar1.TabIndex = 5;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // splitter4

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.splitter4.Dock = System.Windows.Forms.DockStyle.Bottom;

.net中activex的替代技術:winform control(一)

            this.splitter4.Location = new System.Drawing.Point(72, 349);

.net中activex的替代技術:winform control(一)

            this.splitter4.Name = "splitter4";

.net中activex的替代技術:winform control(一)

            this.splitter4.Size = new System.Drawing.Size(494, 2);

.net中activex的替代技術:winform control(一)

            this.splitter4.TabIndex = 6;

.net中activex的替代技術:winform control(一)

            this.splitter4.TabStop = false;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // panel3

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.panel3.Controls.Add(this.listBox1);

.net中activex的替代技術:winform control(一)

            this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;

.net中activex的替代技術:winform control(一)

            this.panel3.Location = new System.Drawing.Point(72, 46);

.net中activex的替代技術:winform control(一)

            this.panel3.Name = "panel3";

.net中activex的替代技術:winform control(一)

            this.panel3.Size = new System.Drawing.Size(494, 303);

.net中activex的替代技術:winform control(一)

            this.panel3.TabIndex = 7;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // listBox1

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;

.net中activex的替代技術:winform control(一)

            this.listBox1.ItemHeight = 12;

.net中activex的替代技術:winform control(一)

            this.listBox1.Location = new System.Drawing.Point(0, 0);

.net中activex的替代技術:winform control(一)

            this.listBox1.Name = "listBox1";

.net中activex的替代技術:winform control(一)

            this.listBox1.Size = new System.Drawing.Size(494, 292);

.net中activex的替代技術:winform control(一)

            this.listBox1.TabIndex = 0;

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            // Demo

.net中activex的替代技術:winform control(一)

            // 

.net中activex的替代技術:winform control(一)

            this.Controls.Add(this.panel1);

.net中activex的替代技術:winform control(一)

            this.Name = "Demo";

.net中activex的替代技術:winform control(一)

            this.Size = new System.Drawing.Size(568, 376);

.net中activex的替代技術:winform control(一)

            this.panel1.ResumeLayout(false);

.net中activex的替代技術:winform control(一)

            this.panel2.ResumeLayout(false);

.net中activex的替代技術:winform control(一)

            this.panel3.ResumeLayout(false);

.net中activex的替代技術:winform control(一)

            this.ResumeLayout(false);

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)

        #endregion

.net中activex的替代技術:winform control(一)

        public string GetUri()

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

        return this.uri;

.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)

        public void SendFiles()

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

            char[] ch=new char[1];

.net中activex的替代技術:winform control(一)

            ch[0]='/';

.net中activex的替代技術:winform control(一)

            string[] arrstr=this.filestr.Split(ch);

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

            WebClient myWebClient = new WebClient(); 

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

            做一存取憑據#region 做一存取憑據

.net中activex的替代技術:winform control(一)

            //NetworkCredential myCred = new NetworkCredential("Administrator","11");//

.net中activex的替代技術:winform control(一)

             //CredentialCache myCache = new CredentialCache();

.net中activex的替代技術:winform control(一)

           //myCache.Add(new Uri(this.uri), "Basic", myCred);

.net中activex的替代技術:winform control(一)

            //myWebClient.Credentials =myCache; 

.net中activex的替代技術:winform control(一)

            #endregion

.net中activex的替代技術:winform control(一)

            //使用預設的權限              

.net中activex的替代技術:winform control(一)

            myWebClient.Credentials =CredentialCache.DefaultCredentials; 

.net中activex的替代技術:winform control(一)

            int count=this.listBox1.Items.Count;

.net中activex的替代技術:winform control(一)

            this.progressBar1.Maximum=10*count;

.net中activex的替代技術:winform control(一)

            for(int i=0;i<arrstr.Length;i++)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

                try 

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

                    string fileNamePath=arrstr[i];

.net中activex的替代技術:winform control(一)

                    string fileName = fileNamePath.Substring(fileNamePath.LastIndexOf("//") + 1); 

.net中activex的替代技術:winform control(一)

                    string uriString = this.uri+"/"+this.serverfolder+"/" + fileName;//指定上傳得路徑 

.net中activex的替代技術:winform control(一)

                    // 要上傳的檔案 

.net中activex的替代技術:winform control(一)

                    FileStream fs = new FileStream(fileNamePath, FileMode.Open, FileAccess.Read); 

.net中activex的替代技術:winform control(一)

                    //FileStream fs = OpenFile(); 

.net中activex的替代技術:winform control(一)

                    BinaryReader r = new BinaryReader(fs); 

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

                    //使用UploadFile方法可以用下面的格式 

.net中activex的替代技術:winform control(一)

                    //                    myWebClient.UploadFile(uriString,"PUT",fileNamePath); 

.net中activex的替代技術:winform control(一)

                    //                    MessageBox.Show(uriString);

.net中activex的替代技術:winform control(一)

                    byte[] postArray = r.ReadBytes((int)fs.Length); 

.net中activex的替代技術:winform control(一)

                    Stream postStream = myWebClient.OpenWrite(uriString,"PUT"); 

.net中activex的替代技術:winform control(一)

                    if(postStream.CanWrite) 

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

.net中activex的替代技術:winform control(一)

                        postStream.Write(postArray,0,postArray.Length); 

.net中activex的替代技術:winform control(一)

                        this.progressBar1.Value=(i+1)*10;

.net中activex的替代技術:winform control(一)

                    } 

.net中activex的替代技術:winform control(一)

                    else 

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

                        MessageBox.Show( "檔案目前不可寫!"); 

.net中activex的替代技術:winform control(一)

                    } 

.net中activex的替代技術:winform control(一)

                    postStream.Close(); 

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

                } 

.net中activex的替代技術:winform control(一)

                catch(WebException errMsg) 

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

                    MessageBox.Show("上傳失敗:" + errMsg.Message); 

.net中activex的替代技術:winform control(一)

                    break;

.net中activex的替代技術:winform control(一)

                } 

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

            if(this.progressBar1.Value==this.progressBar1.Maximum)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

                MessageBox.Show("成功");

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

            else

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            MessageBox.Show("傳送中出現錯誤!");

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)

        private void button1_Click(object sender, System.EventArgs e)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            OpenFileDialog    openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

.net中activex的替代技術:winform control(一)

            openFileDialog1.Multiselect = true;

.net中activex的替代技術:winform control(一)

            openFileDialog1.RestoreDirectory = true;

.net中activex的替代技術:winform control(一)

            openFileDialog1.Filter="dwg檔案|*.dwg";

.net中activex的替代技術:winform control(一)

            openFileDialog1.ShowDialog();

.net中activex的替代技術:winform control(一)

            this.FileListArr=openFileDialog1.FileNames;

.net中activex的替代技術:winform control(一)

            this.listBox1.Items.Clear();

.net中activex的替代技術:winform control(一)

            for(int i=0;i<this.FileListArr.Length;i++)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

                this.listBox1.Items.Add(this.FileListArr[i]);

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

            this.filestr="";

.net中activex的替代技術:winform control(一)

            for(int i=0;i<this.FileListArr.Length;i++)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

                if(this.filestr=="")

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

                    this.filestr=this.FileListArr[i];

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

                }

.net中activex的替代技術:winform control(一)

                else

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

                    this.filestr=this.filestr+"/"+this.FileListArr[i];

.net中activex的替代技術:winform control(一)

                }

.net中activex的替代技術:winform control(一)

            }

.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

        private void button2_Click(object sender, System.EventArgs e)

.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)
.net中activex的替代技術:winform control(一)

{

.net中activex的替代技術:winform control(一)

            this.SendFiles();

.net中activex的替代技術:winform control(一)

        }

.net中activex的替代技術:winform control(一)

    }

.net中activex的替代技術:winform control(一)

}

.net中activex的替代技術:winform control(一)