然后建立文件上传窗体

代码:
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


{

/**//// <summary>
/// frm_WriteAttach 的摘要说明。
/// </summary>
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;

/**//// <summary>
/// 获得上传是否成功信息
/// </summary>
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 窗体设计器生成的代码

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
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();
}
}
}
}
然后建立文件下载窗体:

代码如下:
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


{

/**//// <summary>
/// 功能:文件下载
/// </summary>
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;

/**//// <summary>
/// 获得下载是否成功信息
/// </summary>
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 窗体设计器生成的代码

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
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();
}
}
}
}
相关文章:
-
2021-11-15
-
2021-07-04
-
2021-12-26
-
2021-12-12
-
2022-02-18
-
2021-04-17
-
2021-12-12
猜你喜欢
-
2021-11-17
-
2021-12-26
-
2021-04-28
-
2022-01-29
-
2022-01-30
-
2021-11-17
-
2021-06-19
相关资源
-
下载
2021-06-05
-
下载
2021-06-06
-
下载
2023-03-23