设为首页 收藏本站
查看: 1409|回复: 0

运用Ftp进行文件上传(二)

[复制链接]

尚未签到

发表于 2015-5-28 11:02:37 | 显示全部楼层 |阅读模式
  然后建立文件上传窗体
DSC0000.jpg
代码:


DSC0001.gif using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using DevExpress.XtraEditors;
using System.Net;
using System.IO;
using System.Text;
using System.Net.Sockets;

namespace WindowsApplication6
DSC0002.gif DSC0003.gif DSC0004.gif {
DSC0005.gif DSC0006.gif     /**////
DSC0007.gif     /// frm_WriteAttach 的摘要说明。
DSC0008.gif     ///
    public class frm_WriteAttach : System.Windows.Forms.Form
    {
        private DevExpress.XtraEditors.ProgressBarControl progressBarControl1;
        private string strFileName = "";
        private string strGuid = "";
        private System.ComponentModel.IContainer components;
   
        //是否传输成功
        private bool I_Transfer;
        /**////
        /// 获得上传是否成功信息
        ///
        public bool b_Transfer
        {
            get
            {
                return I_Transfer;
            }
        }

        public frm_WriteAttach(string s1,string s2)
        {
            //
            // Windows 窗体设计器支持所必需的
            //
            
            InitializeComponent();
            this.strFileName = s1;
            this.strGuid = s2;

            //
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            //
        }
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
        /**////
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        ///
        private void InitializeComponent()
        {
            this.progressBarControl1 = new DevExpress.XtraEditors.ProgressBarControl();
            ((System.ComponentModel.ISupportInitialize)(this.progressBarControl1.Properties)).BeginInit();
            this.SuspendLayout();
            //
            // progressBarControl1
            //
            this.progressBarControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.progressBarControl1.Location = new System.Drawing.Point(0, 0);
            this.progressBarControl1.Name = "progressBarControl1";
            //
            // progressBarControl1.Properties
            //
            this.progressBarControl1.Properties.LookAndFeel.SkinName = "Coffee";
            this.progressBarControl1.Properties.LookAndFeel.UseDefaultLookAndFeel = false;
            this.progressBarControl1.Properties.ShowTitle = true;
            this.progressBarControl1.Size = new System.Drawing.Size(362, 24);
            this.progressBarControl1.TabIndex = 0;
            this.progressBarControl1.TabStop = false;
            //
            // frm_WriteAttach
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(362, 24);
            this.ControlBox = false;
            this.Controls.Add(this.progressBarControl1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Name = "frm_WriteAttach";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "文件上传";
            this.Load += new System.EventHandler(this.frm_WriteAttach_Load);
            ((System.ComponentModel.ISupportInitialize)(this.progressBarControl1.Properties)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        private void frm_WriteAttach_Load(object sender, System.EventArgs e)
        {
            Thread thd = new Thread(new ThreadStart(this.BeginProcess));
            thd.Start();
        }
   

        private void BeginProcess()
        {
            FileOperator op = new FileOperator();
            if(op.writeAttach(this.strFileName,this.strGuid,this.progressBarControl1))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("附件上传成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                I_Transfer=true;
                this.Close();               
            }
            else
            {
                I_Transfer=false;
                this.Close();
            }
               
        }
    }
DSC0009.gif }

然后建立文件下载窗体:


代码如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using DevExpress.XtraEditors;
using System.Net;
using System.IO;
using System.Text;
using System.Net.Sockets;
namespace WindowsApplication6
{
    /**////
    /// 功能:文件下载
    ///
    public class frm_ReadAttach : System.Windows.Forms.Form
    {
        private DevExpress.XtraEditors.ProgressBarControl progressBarControl1;
        //保存到本地的文件名称
        private string strFileName = "";
        //文件要下载的路径
        private string strPath = "";
        //Ftp上面的文件名称相同
        private string str_ftp="";
        private System.ComponentModel.IContainer components;
   
        //是否传输成功
        private bool I_Transfer;
        /**////
        /// 获得下载是否成功信息
        ///
        public bool b_Transfer
        {
            get
            {
                return I_Transfer;
            }
        }
        
        public frm_ReadAttach(string s1,string s2,string s3)
        {
            //
            // Windows 窗体设计器支持所必需的
            //
            
            InitializeComponent();   
        
            this.str_ftp=s1;
            this.strPath = s2;
            this.strFileName = s3;
            //
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            //
        }
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
        /**////
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        ///
        private void InitializeComponent()
        {
            this.progressBarControl1 = new DevExpress.XtraEditors.ProgressBarControl();
            ((System.ComponentModel.ISupportInitialize)(this.progressBarControl1.Properties)).BeginInit();
            this.SuspendLayout();
            //
            // progressBarControl1
            //
            this.progressBarControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.progressBarControl1.Location = new System.Drawing.Point(0, 0);
            this.progressBarControl1.Name = "progressBarControl1";
            //
            // progressBarControl1.Properties
            //
            this.progressBarControl1.Properties.LookAndFeel.SkinName = "Coffee";
            this.progressBarControl1.Properties.LookAndFeel.UseDefaultLookAndFeel = false;
            this.progressBarControl1.Properties.ShowTitle = true;
            this.progressBarControl1.Size = new System.Drawing.Size(362, 24);
            this.progressBarControl1.TabIndex = 0;
            this.progressBarControl1.TabStop = false;
            //
            // frm_WriteAttach
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(362, 24);
            this.ControlBox = false;
            this.Controls.Add(this.progressBarControl1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Name = "frm_WriteAttach";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "文件下载";
            this.Load += new System.EventHandler(this.frm_WriteAttach_Load);
            ((System.ComponentModel.ISupportInitialize)(this.progressBarControl1.Properties)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        private void frm_WriteAttach_Load(object sender, System.EventArgs e)
        {
            Thread thd = new Thread(new ThreadStart(this.BeginProcess));
            thd.Start();
        }
   

        private void BeginProcess()
        {
            FileOperator op = new FileOperator();
            try
            {
                op.getAttach(this.str_ftp,this.strPath,this.strFileName,this.progressBarControl1);
                if (!op.b_OperatorSign)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("附件下载失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    I_Transfer = false;
                    this.Close();
                }
                else
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show("附件下载成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    I_Transfer = true;
                    this.Close();
                }

               
            }
            catch
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("附件下载失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                I_Transfer = false;
                this.Close();
            }
               
        }
    }
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-71442-1-1.html 上篇帖子: linux--ftp命令大全 下篇帖子: dos登陆FTP的方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表