运用Ftp进行文件上传(二)
然后建立文件上传窗体
代码:
 using System;
using System; using System.Drawing;
using System.Drawing; using System.Collections;
using System.Collections; using System.ComponentModel;
using System.ComponentModel; using System.Windows.Forms;
using System.Windows.Forms; using System.Threading;
using System.Threading; using DevExpress.XtraEditors;
using DevExpress.XtraEditors; using System.Net;
using System.Net; using System.IO;
using System.IO; using System.Text;
using System.Text; using System.Net.Sockets;
using System.Net.Sockets;
 namespace WindowsApplication6
namespace WindowsApplication6 {
{ /// <summary>
    /// <summary> /// frm_WriteAttach 的摘要说明。
    /// frm_WriteAttach 的摘要说明。 /// </summary>
    /// </summary> public class frm_WriteAttach : System.Windows.Forms.Form
    public class frm_WriteAttach : System.Windows.Forms.Form {
    { private DevExpress.XtraEditors.ProgressBarControl progressBarControl1;
        private DevExpress.XtraEditors.ProgressBarControl progressBarControl1; private string strFileName = "";
        private string strFileName = ""; private string strGuid = "";
        private string strGuid = ""; private System.ComponentModel.IContainer components;
        private System.ComponentModel.IContainer components; 
     //是否传输成功
        //是否传输成功 private bool I_Transfer;
        private bool I_Transfer; /// <summary>
        /// <summary> /// 获得上传是否成功信息
        /// 获得上传是否成功信息 /// </summary>
        /// </summary> public bool b_Transfer
        public bool b_Transfer {
        { get
            get {
            { return I_Transfer;
                return I_Transfer; }
            } }
        }
 public frm_WriteAttach(string s1,string s2)
        public frm_WriteAttach(string s1,string s2) {
        { //
            // // Windows 窗体设计器支持所必需的
            // Windows 窗体设计器支持所必需的 //
            // 
             InitializeComponent();
            InitializeComponent(); this.strFileName = s1;
            this.strFileName = s1; this.strGuid = s2;
            this.strGuid = s2;
 //
            // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 //
            // }
        } protected override void Dispose( bool disposing )
        protected override void Dispose( bool disposing ) {
        { if( disposing )
            if( disposing ) {
            { if(components != null)
                if(components != null) {
                { components.Dispose();
                    components.Dispose(); }
                } }
            } base.Dispose( disposing );
            base.Dispose( disposing ); }
        }
 Windows 窗体设计器生成的代码
        Windows 窗体设计器生成的代码
 private void frm_WriteAttach_Load(object sender, System.EventArgs e)
        private void frm_WriteAttach_Load(object sender, System.EventArgs e) {
        { Thread thd = new Thread(new ThreadStart(this.BeginProcess));
            Thread thd = new Thread(new ThreadStart(this.BeginProcess)); thd.Start();
            thd.Start(); }
        } 
    
 private void BeginProcess()
        private void BeginProcess() {
        { FileOperator op = new FileOperator();
            FileOperator op = new FileOperator(); if(op.writeAttach(this.strFileName,this.strGuid,this.progressBarControl1))
            if(op.writeAttach(this.strFileName,this.strGuid,this.progressBarControl1)) {
            { DevExpress.XtraEditors.XtraMessageBox.Show("附件上传成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                DevExpress.XtraEditors.XtraMessageBox.Show("附件上传成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); I_Transfer=true;
                I_Transfer=true; this.Close();
                this.Close();                 }
            } else
            else {
            { I_Transfer=false;
                I_Transfer=false; this.Close();
                this.Close(); }
            } 
                 }
        } }
    } }
}
然后建立文件下载窗体:

代码如下:
 using System;
using System; using System.Drawing;
using System.Drawing; using System.Collections;
using System.Collections; using System.ComponentModel;
using System.ComponentModel; using System.Windows.Forms;
using System.Windows.Forms; using System.Threading;
using System.Threading; using DevExpress.XtraEditors;
using DevExpress.XtraEditors; using System.Net;
using System.Net; using System.IO;
using System.IO; using System.Text;
using System.Text; using System.Net.Sockets;
using System.Net.Sockets; namespace WindowsApplication6
namespace WindowsApplication6 {
{ /// <summary>
    /// <summary> /// 功能:文件下载
    /// 功能:文件下载 /// </summary>
    /// </summary> public class frm_ReadAttach : System.Windows.Forms.Form
    public class frm_ReadAttach : System.Windows.Forms.Form {
    { private DevExpress.XtraEditors.ProgressBarControl progressBarControl1;
        private DevExpress.XtraEditors.ProgressBarControl progressBarControl1; //保存到本地的文件名称
        //保存到本地的文件名称 private string strFileName = "";
        private string strFileName = ""; //文件要下载的路径
        //文件要下载的路径 private string strPath = "";
        private string strPath = ""; //Ftp上面的文件名称相同
        //Ftp上面的文件名称相同 private string str_ftp="";
        private string str_ftp=""; private System.ComponentModel.IContainer components;
        private System.ComponentModel.IContainer components; 
     //是否传输成功
        //是否传输成功 private bool I_Transfer;
        private bool I_Transfer; /// <summary>
        /// <summary> /// 获得下载是否成功信息
        /// 获得下载是否成功信息 /// </summary>
        /// </summary> public bool b_Transfer
        public bool b_Transfer {
        { get
            get {
            { return I_Transfer;
                return I_Transfer; }
            } }
        } 
         public frm_ReadAttach(string s1,string s2,string s3)
        public frm_ReadAttach(string s1,string s2,string s3) {
        { //
            // // Windows 窗体设计器支持所必需的
            // Windows 窗体设计器支持所必需的 //
            // 
             InitializeComponent();
            InitializeComponent();     
         this.str_ftp=s1;
            this.str_ftp=s1; this.strPath = s2;
            this.strPath = s2; this.strFileName = s3;
            this.strFileName = s3; //
            // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 //
            // }
        } protected override void Dispose( bool disposing )
        protected override void Dispose( bool disposing ) {
        { if( disposing )
            if( disposing ) {
            { if(components != null)
                if(components != null) {
                { components.Dispose();
                    components.Dispose(); }
                } }
            } base.Dispose( disposing );
            base.Dispose( disposing ); }
        }
 Windows 窗体设计器生成的代码
        Windows 窗体设计器生成的代码
 private void frm_WriteAttach_Load(object sender, System.EventArgs e)
        private void frm_WriteAttach_Load(object sender, System.EventArgs e) {
        { Thread thd = new Thread(new ThreadStart(this.BeginProcess));
            Thread thd = new Thread(new ThreadStart(this.BeginProcess)); thd.Start();
            thd.Start(); }
        } 
    
 private void BeginProcess()
        private void BeginProcess() {
        { FileOperator op = new FileOperator();
            FileOperator op = new FileOperator(); try
            try {
            { op.getAttach(this.str_ftp,this.strPath,this.strFileName,this.progressBarControl1);
                op.getAttach(this.str_ftp,this.strPath,this.strFileName,this.progressBarControl1); if (!op.b_OperatorSign)
                if (!op.b_OperatorSign) {
                { DevExpress.XtraEditors.XtraMessageBox.Show("附件下载失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    DevExpress.XtraEditors.XtraMessageBox.Show("附件下载失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); I_Transfer = false;
                    I_Transfer = false; this.Close();
                    this.Close(); }
                } else
                else {
                { DevExpress.XtraEditors.XtraMessageBox.Show("附件下载成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    DevExpress.XtraEditors.XtraMessageBox.Show("附件下载成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); I_Transfer = true;
                    I_Transfer = true; this.Close();
                    this.Close(); }
                }
 
                 }
            } catch
            catch {
            { DevExpress.XtraEditors.XtraMessageBox.Show("附件下载失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                DevExpress.XtraEditors.XtraMessageBox.Show("附件下载失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); I_Transfer = false;
                I_Transfer = false; this.Close();
                this.Close(); }
            } 
                 }
        } }
    } }
} 
                    
                

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号