基本信息
源码名称:C# 文件上传与下载工具源码(含服务端以及客户端)
源码大小:0.05M
文件格式:.zip
开发语言:C#
更新时间:2018-11-14
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
这个文件管理的引擎实现的功能是对所有客户端上传的文件信息进行管理,客户端在上传或是下载的时候允许进度报告。如果我们只是显示一个文件发送到服务器上,服务器接收数据后保存到本地,那么这是非常容易实现的,只要比较熟悉网络通信就可以,但是对于文件服务器引擎需要的逻辑更多,允许上传额外的信息,包括文件的上传人,上传日期,下载次数等等信息,然后允许上传的时候不影响下载,可以同时下载,同时上传,而服务器的硬盘IO不进行阻塞,这样实现起来就相当困难了,但是上述所有的功能在使用本组件实现的时候就非常的方便,当客户端进行上传下载的时候更是调用一个方法就能完成。







服务器端代码

using HslCommunication.Enthernet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace File.Server
{
    public partial class FormServer : Form
    {
        public FormServer()
        {
            InitializeComponent();
        }

        #region 服务器端代码
        
        private UltimateFileServer ultimateFileServer;                                            // 引擎对象

        private void UltimateFileServerInitialization()
        {
            ultimateFileServer = new UltimateFileServer();                                        // 实例化对象
            ultimateFileServer.KeyToken = new Guid("A8826745-84E1-4ED4-AE2E-D3D70A9725B5");       // 指定一个令牌
            ultimateFileServer.LogNet = new HslCommunication.LogNet.LogNetSingle(Application.StartupPath   @"\Logs\123.txt");
            ultimateFileServer.FilesDirectoryPath = Application.StartupPath   @"\UltimateFile";   // 所有文件存储的基础路径
            ultimateFileServer.ServerStart(34567);                                                // 启动一个端口的引擎

            // 订阅一个目录的信息,使用文件集容器实现
            GroupFileContainer container = ultimateFileServer.GetGroupFromFilePath(Application.StartupPath   @"\UltimateFile\Files\Personal\Admin");
            container.FileCountChanged  = Container_FileCountChanged;                         // 当文件数量发生变化时触发
        }

        private void Container_FileCountChanged(int obj)
        {
            if (InvokeRequired)
            {
                Invoke(new Action<int>(Container_FileCountChanged), obj);
                return;
            }

            label1.Text = "文件数量:"   obj.ToString();
        }

        private void userButton1_Click(object sender, EventArgs e)
        {
            // 点击了启动服务器端的文件引擎
            UltimateFileServerInitialization();
            userButton1.Enabled = false;
        }
        
        #endregion


    }
}