文件上传下载(C#,web,asp.net)

1、上传下载CS客户端程序 

采用C#开发语言开发,wpf界面,webclient等接口,http协议,实现数据的上传下载功能,实现文件记录写入后台数据库mysql中。   exe

2、注册程序(参考某博客资料)

采用C#开发语言,win32的相关注册表操作接口,实现上传下载程序写入注册表,以便前端页面调用 。   exe

3、文件上传后台程序

采用asp.net 技术,IIS,接收上传下载客户端程序的文件上传请求,实现服务器端文件的保存,以及照片缩略图的生成与保存。 axpx

4、前端页面功能入口

采用easyUI技术,javascript技术,实现上传下载程序的下载以及调用。html

=======================================================================

1、html页面启动功能

2、启动客户端程序

3、下载

4、上传

=====================================================================

1、上传下载CS客户端程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YpGlobalWPF;
using YpGlobalWPF.Dialog;

namespace UpDownLoadApp
{
    class StartUpApp
    {
        [STAThread]
        public static void Main(string[] args)
        {
            //string[] s = { "yupontuploadapp://192.168.120.200_guangzhou_root_root_http://192.168.120.200/Data_http://192.168.120.200/uploadFileServer/Default.aspx" };
            //args = s;
            if (args.Length<1)
            {
                return;
            }
            ParseExePara(args);
            App app = new App();
            app.InitializeComponent();
            app.Run();
            return;
        }

        public static void  ParseExePara(string[] args)
        {
            if (args.Length<1)
            {
                return;                
            }
            string paraRemoved = "yupontuploadapp://";
            string para = args[0];
            para = para.Replace(paraRemoved, "").Trim();
            if (!string.IsNullOrWhiteSpace(para)&&para.Length>0)
            {
                string[] allParas=para.Split('_');
                if (allParas.Length<4)
                {
                    return;
                }
                YpGlobalWPF.CommonUtil.Para = new CommonUtils.MySqlConnPara()
                {
                    Host = allParas[0],
                    DataBase = allParas[1],
                    UserName = allParas[2],
                    Password = allParas[3]
                };
                if (allParas.Length>4)
                {
                    YpGlobalWPF.CommonUtil.CesiumDataBaseUrl = allParas[4];
                    string upLoadFilePathRelative;
                    if (allParas[4].Contains("127.0.0.1"))
                    {
                        upLoadFilePathRelative = YBCommonUtility.StringUtility.GetAfterRemovePreStr(allParas[4], "127.0.0.1");
                    }
                    else if (allParas[4].Contains("localhost"))
                    {
                        upLoadFilePathRelative = YBCommonUtility.StringUtility.GetAfterRemovePreStr(allParas[4], "localhost");
                    }
                    else
                    {
                        upLoadFilePathRelative = YBCommonUtility.StringUtility.GetAfterRemovePreStr(allParas[4], YpGlobalWPF.CommonUtil.Para.Host);
                    }
                    YpGlobalWPF.CommonUtil.UpLoadDataDirRelative = upLoadFilePathRelative;
                    YpGlobalWPF.CommonUtil.SourceFilePath = allParas[4]+"/images/原始数据";
                    YpGlobalWPF.CommonUtil.FaultFilePath = allParas[4] + "/images/缺陷数据";
                }
                if (allParas.Length>5)
                {
                    YpGlobalWPF.CommonUtil.ServerAspx = allParas[5];
                }
            }
        }
    }
}

//using DbDAL;
//using DbModel;
using System;
using System.Collections.Generic;
//using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using YpGlobalWPF.Common;
using System.ComponentModel;
using System.Threading;
namespace YpGlobalWPF.Dialog
{
    /// <summary>
    /// frmLineProfile.xaml 的交互逻辑
    /// </summary>
    public partial class frmPictureTreeDownFile : Window,INotifyPropertyChanged
    {
        private IDictionary<string, string> _pictures;
        private bool _bMaximized = false;
        
        private string _lineName="";

        private string _poleName="";

        private string _baseUrl = "";
        public string PoleName
        {
            get { return _poleName; }
            set
            {
                _poleName = value;
                LinePoleName = _lineName + _poleName;
                RaisePropertyChanged("PoleName");
            }
        }

        private string linePoleName;

        public string LinePoleName
        {
            get { return linePoleName; }
            set
            {
                linePoleName = value;
                RaisePropertyChanged("LinePoleName");
            }
        }

        private static frmPictureTreeDownFile picTree1;

        public static frmPictureTreeDownFile Instance
        {
            get 
            {
                if (picTree1 == null)
                {
                    picTree1 = new frmPictureTreeDownFile(null);
                }
                return picTree1; 
            }
            set
            {
                picTree1 = value;
            }
            
        }

        public frmPictureTreeDownFile(IDictionary<string, string> pics)
        {
            InitializeComponent();
            _pictures = pics;
            //
            double scale = CommonUtil.ScaleValue;
            //this.Width = 950 * scale;
            //this.Height = 700 * scale;
        }

        public bool Init(string baseUrl,string lineName,string poleName)
        {
            try
            {
                this._lineName = lineName;
                this.PoleName = poleName;
                this._baseUrl = baseUrl;
                ViewModel.VM_PicTreeDownFile picTreeViewModel = new ViewModel.VM_PicTreeDownFile();
                picTreeViewModel.LoadDataOnCommand(baseUrl, true, true);
                if (picTreeViewModel.Children == null || picTreeViewModel.Children.Count == 0 )
                {
                    CommonUtil.ShowMessage("提示", "没找到照片!");
                    return false;
                }
                frmPictureTreeDownFile.Instance.picTree.DataContext = picTreeViewModel;

                List<NameValueItem> cmbLineSource = picTreeViewModel.GetCmbLines();
                cmbLineSource.Insert(0,new NameValueItem("全部","全部"));
                frmPictureTreeDownFile.Instance.cmbLines.ItemsSource = cmbLineSource;
                frmPictureTreeDownFile.Instance.cmbLines.SelectedValue = lineName;
                frmPictureTreeDownFile.Instance.cmbLines_SelectionChanged(null, null);

                FillCmbPoles(lineName, poleName, picTreeViewModel);
                
                
            }
            catch (Exception)
            {
                CommonUtil.ShowMessage("提示", "打开杆塔照片出错!");
                return false;
            }
            
            return true;
        }

        private void FillCmbPoles(string lineName,string poleName,ViewModel.VM_PicTreeDownFile picTreeViewModel)
        {
            List<NameValueItem> cmbPoleSource = picTreeViewModel.GetLinePoles(lineName);
            if (cmbPoleSource==null)
            {
                return;
            }
            cmbPoleSource.Insert(0, new NameValueItem("全部", "全部"));
            frmPictureTreeDownFile.Instance.cmbPoles.ItemsSource = cmbPoleSource;
            if (poleName==null)
            {
                frmPictureTreeDownFile.Instance.cmbPoles.SelectedIndex = 0;
                return;
            }
            else
            {
                if (cmbPoleSource.Count>1)
                {
                    if (cmbPoleSource[1].Value.ToString().EndsWith("#"))
                    {
                        poleName = poleName.Replace("", "#");
                        if (!poleName.EndsWith("#"))
                        {
                            poleName += "#";
                        }
                    }                    
                    if (cmbPoleSource[1].Value.ToString().EndsWith(""))
                    {
                        poleName = poleName.Replace("#", "");
                        if (!poleName.EndsWith(""))
                        {
                            poleName += "";
                        }
                    }
                    
                }
                frmPictureTreeDownFile.Instance.cmbPoles.SelectedValue = poleName;
            }            
            frmPictureTreeDownFile.Instance.cmbPoles_SelectionChanged(null, null);
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Hidden;
        }

        private bool _bMouseDown;
        private System.Windows.Point _startPoint;
        private void Gripe_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _bMouseDown = true;
            _startPoint = e.GetPosition(this);
            sizeGripe.CaptureMouse();
            this.Cursor = Cursors.SizeAll;
        }

        private void Gripe_MouseMove(object sender, MouseEventArgs e)
        {
            if (_bMouseDown)
            {
                System.Windows.Point endPos = e.GetPosition(this);
                this.Width = this.Width + (endPos.X - _startPoint.X);
                this.Height = this.Height + (endPos.Y - _startPoint.Y);
                _startPoint = endPos;
            }
        }

        private void Gripe_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _bMouseDown = false;
            sizeGripe.ReleaseMouseCapture();
            this.Cursor = Cursors.Arrow;
        }

        private TextBlock curSelectedItme = null;

        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //ViewModel.VM_PicTree treeItem = (sender as TextBlock).Tag as ViewModel.VM_PicTree;
            curSelectedItme = sender as TextBlock;//
        }
        
        public event PropertyChangedEventHandler PropertyChanged;

        private void  RaisePropertyChanged(string propName)
        {
            if (PropertyChanged!=null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {

        }

        private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.Visibility = Visibility.Hidden;
        }

        private void btnDownFile_Click(object sender, RoutedEventArgs e)
        {
            ViewModel.VM_PicTreeDownFile vmTree = (ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext;
            if (!Directory.Exists(this.txtSavePath.Text.Trim()))
            {
                CommonUtil.ShowMessage("错误", "保存目录设置错误!");
                txtSavePath.Text = "";
                txtSavePath.Focus();
                return;
            }
            this.waitP.Visibility = Visibility.Visible;
            System.Windows.Forms.Application.DoEvents();
            Thread newThread = new Thread(
                         new ParameterizedThreadStart(down));
            Tuple<ViewModel.VM_PicTreeDownFile, string> tt = new Tuple<ViewModel.VM_PicTreeDownFile, string>(vmTree, this.txtSavePath.Text.Trim());
            
            newThread.IsBackground = true;
            newThread.Start(tt);
            
            //vmTree.DownFile(vmTree,this.txtSavePath.Text.Trim());
            
        }

        private void down(Object para1)
        {
            Tuple<ViewModel.VM_PicTreeDownFile, string> para = para1 as Tuple<ViewModel.VM_PicTreeDownFile, string>;
            para.Item1.DownFile(para.Item1, para.Item2);
            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                this.waitP.Visibility = Visibility.Collapsed;
                CommonUtil.ShowMessage("提示", "数据下载完成!");
            }));
        }

        private void formCaption_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            _bMaximized = !_bMaximized;
            if (_bMaximized)
            {
                this.WindowState = System.Windows.WindowState.Maximized;
            }
            else
            {
                this.WindowState = System.Windows.WindowState.Normal;
            }
        }

        private void formCaption_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

        private void cmbLines_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbLines.SelectedValue==null)
            {
                return;
            }
            string lineName = cmbLines.SelectedValue.ToString();
            ((ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext).SearchTree(lineName, this._baseUrl);
            FillCmbPoles(lineName, null, (ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext);
        }

        private void btnselpath_Click(object sender, RoutedEventArgs e)
        {
            string fullFilePath = string.Empty;
            System.Windows.Forms.FolderBrowserDialog dilog = new System.Windows.Forms.FolderBrowserDialog();
            dilog.Description = "请选择文件夹";
            if (dilog.ShowDialog() == System.Windows.Forms.DialogResult.OK || dilog.ShowDialog() == System.Windows.Forms.DialogResult.Yes)
            {
                fullFilePath = dilog.SelectedPath;
            }
            txtSavePath.Text = fullFilePath;
        }

        private void cmbPoles_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbPoles.SelectedValue == null)
            {
                return;
            }
            if (((ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext).Children[0].Children.Count == 0)
            {
                return;
            }
            //int lineNameIndex = -1;
            string poleName = cmbPoles.SelectedValue.ToString();
            string lineName = cmbLines.SelectedValue.ToString();
            //((ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext).GetLineNameIndex((ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext, _lineName, ref lineNameIndex);//获取线路名称的索引
            //if (lineNameIndex > 0)
            //{
            //    ((ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext).SearchTreePoles(lineNameIndex + (_baseUrl.Equals(CommonUtil.PolePicturePath) ? 2 : 1), poleName,_baseUrl);
            //}
            if(((ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext).Children.Count==0)
            {
                return;
            }
            ((ViewModel.VM_PicTreeDownFile)frmPictureTreeDownFile.Instance.picTree.DataContext).SearchTreePoles2(lineName, poleName, _baseUrl);
        }

        
    }

}
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace UpDownLoadApp.View
{
    /// <summary>
    /// UploadFile.xaml 的交互逻辑
    /// </summary>
    public partial class frmUploadFile : Window
    {
        string _currentPath = "";//选择的要上传的文件夹路径
        private bool _bMouseDown;
        private System.Windows.Point _startPoint;
        private bool _bMaximized = false;
        private int _removeRecordIndex = 0;
        private ObservableCollection<Model.LogModel> _AllLog = new ObservableCollection<Model.LogModel>();
        private ObservableCollection<Model.LogModel> _curAllLog = new ObservableCollection<Model.LogModel>();

        public frmUploadFile()
        {
            InitializeComponent();
            InitCmb();
            this.lstLog.ItemsSource = _curAllLog;
        }

        private static frmUploadFile picTree1;

        public static frmUploadFile Instance
        {
            get
            {
                if (picTree1 == null)
                {
                    picTree1 = new frmUploadFile();
                }
                return picTree1;
            }
            set
            {
                picTree1 = value;
            }

        }

        private void InitCmb()
        {
            this.cmbDataType.ItemsSource = Enum.GetNames(typeof(Model.enumDataType));
            if (this.cmbDataType.Items!=null&&this.cmbDataType.Items.Count>0)
            {
                this.cmbDataType.SelectedIndex = 0;
            }
            if (cmbDataType.SelectedIndex == 0)
            {
                this.cmbDataLevel.ItemsSource = Enum.GetNames(typeof(Model.enumSourceFileLevelType));
            }
            else
            {
                this.cmbDataLevel.ItemsSource = Enum.GetNames(typeof(Model.enumFaultFileLevelType));
            }
            if (this.cmbDataLevel.Items != null && this.cmbDataLevel.Items.Count > 0)
            {
                this.cmbDataLevel.SelectedIndex = 0;
            }
            this.cmbDataType.SelectionChanged += (s, e) =>
            {
                if (cmbDataType.SelectedIndex==0)
                {
                    this.cmbDataLevel.ItemsSource = Enum.GetNames(typeof(Model.enumSourceFileLevelType));
                }
                else
                {
                    this.cmbDataLevel.ItemsSource = Enum.GetNames(typeof(Model.enumFaultFileLevelType));
                }
                if (this.cmbDataLevel.Items!=null&&this.cmbDataLevel.Items.Count>0)
                {
                    this.cmbDataLevel.SelectedIndex = 0;
                }
            };
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {

        }

        private void formCaption_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            _bMaximized = !_bMaximized;
            if (_bMaximized)
            {
                this.WindowState = System.Windows.WindowState.Maximized;
            }
            else
            {
                this.WindowState = System.Windows.WindowState.Normal;
            }
        }

        private void formCaption_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.Visibility = Visibility.Hidden;
        }

        private void Gripe_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _bMouseDown = true;
            _startPoint = e.GetPosition(this);
            sizeGripe.CaptureMouse();
            this.Cursor = Cursors.SizeAll;
        }

        private void Gripe_MouseMove(object sender, MouseEventArgs e)
        {
            if (_bMouseDown)
            {
                System.Windows.Point endPos = e.GetPosition(this);
                this.Width = this.Width + (endPos.X - _startPoint.X);
                this.Height = this.Height + (endPos.Y - _startPoint.Y);
                _startPoint = endPos;
            }
        }

        private void Gripe_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _bMouseDown = false;
            sizeGripe.ReleaseMouseCapture();
            this.Cursor = Cursors.Arrow;
        }

        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDownFile_Click(object sender, RoutedEventArgs e)
        {
            _removeRecordIndex = 0;
            chkAllLog.IsChecked = true;
            _curAllLog.Clear();
            _AllLog.Clear();
            string serverAspx = YpGlobalWPF.CommonUtil.ServerAspx;//服务器端网页
            ViewModel.UpLoadFile upLoadFile = new ViewModel.UpLoadFile(ViewModel.UpLoadFile.GetDataBaseType(_currentPath));
            upLoadFile.proBarEvent += updataH_ProcessChanged;
            upLoadFile.LogMessageEvent += upLoadFile_LogMessageEvent;
            upLoadFile.UpLoadDir(_currentPath,serverAspx);
        }


        void upLoadFile_LogMessageEvent(string log)
        {
            _AllLog.Add(new Model.LogModel { Message = log });
            if (_AllLog.Count>100)
            {
                if(_AllLog[_removeRecordIndex].Message.Contains("失败"))
                {
                    _AllLog.RemoveAt(_removeRecordIndex);
                }
                else
                {
                    if (_removeRecordIndex<_AllLog.Count-1)
                    {
                        _removeRecordIndex++;
                    }                    
                }
            }
            if (_AllLog.Count>200)
            {
                _AllLog.RemoveAt(0);
            }
            _curAllLog.Clear();
            foreach (var item in _AllLog)
            {
                _curAllLog.Add(item);
            }
            System.Windows.Forms.Application.DoEvents();
        }

        void updataH_ProcessChanged(int TotalCount, int curCount)
        {
            this.proBar.Value = (int)Math.Round((double)(curCount * 100) / TotalCount, 2);
            System.Windows.Forms.Application.DoEvents();
            if (curCount >= TotalCount)
            {
                MessageBox.Show("上传完成!");
            }
        }
        
        private void btnselpath_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string fullFilePath = string.Empty;
                System.Windows.Forms.FolderBrowserDialog dilog = new System.Windows.Forms.FolderBrowserDialog();
                dilog.Description = "请选择文件夹";
                dilog.SelectedPath = _currentPath;
                System.Windows.Forms.DialogResult dlgResult = dilog.ShowDialog();
                if (dlgResult == System.Windows.Forms.DialogResult.OK || dlgResult == System.Windows.Forms.DialogResult.Yes)
                {
                    fullFilePath = dilog.SelectedPath;
                    this.txtInputPath.Text = fullFilePath;
                    _currentPath = dilog.SelectedPath;
                    ReSetCmb(fullFilePath);
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.ToString());
            }
        }

        private void ReSetCmb(string filefPath)
        {
            string type = ViewModel.UpLoadFile.GetDataBaseType(filefPath);
            string levelType = ViewModel.UpLoadFile.GetFileLevelType(filefPath);
            if (type.Equals(Model.enumDataType.原始数据.ToString()))
            {                
                this.cmbDataType.SelectedIndex = 0;
            }
            else if (type.Equals(Model.enumDataType.缺陷数据.ToString()))
            {
                this.cmbDataType.SelectedIndex = 1;
            }
            this.cmbDataLevel.SelectedItem = levelType;
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Hidden;
        }

        private void chkAllLog_Checked(object sender, RoutedEventArgs e)
        {
            _curAllLog.Clear();
            foreach (var item in _AllLog)
            {
                _curAllLog.Add(item);
            }
        }

        private void chkSucceLog_Checked(object sender, RoutedEventArgs e)
        {
            IEnumerable<Model.LogModel> a = _AllLog.Where(t => t.Message.Contains("成功"));
            _curAllLog.Clear();
            foreach (var item in a)
            {
                _curAllLog.Add(item);
            }
        }

        private void chkFailLog_Checked(object sender, RoutedEventArgs e)
        {
            IEnumerable<Model.LogModel> a = _AllLog.Where(t => t.Message.Contains("失败"));
            _curAllLog.Clear();
            foreach (var item in a)
            {
                _curAllLog.Add(item);
            }
        }

    }
}

2、注册程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RegisterUpLoadApp
{
    class Program
    {
        public const string KEYNAME = "yupontuploadapp";
        public const string EXENAME = "UpDownLoadApp.exe";
        static void Main(string[] args)
        {
            string regeditExePath=System.AppDomain.CurrentDomain.BaseDirectory;
            regeditExePath = System.IO.Path.Combine(regeditExePath, @"UpLoadClient\");
            RegeditManager.InstallerDemo_AfterUninstall(KEYNAME, regeditExePath);
            RegeditManager.InstallerDemo_AfterInstall(regeditExePath, EXENAME, KEYNAME);
            Console.ReadKey();
        }
    }
}
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace RegisterUpLoadApp
{
    public class RegeditManager
    {
        
        /// <summary>
        ////// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void InstallerDemo_AfterInstall(string targetdirPath, string exeName,string regeditKeyName)
        {
            Msg("文件路径:" + Path.Combine(targetdirPath, exeName), targetdirPath);
            var result = RegeditAdd(regeditKeyName, Path.Combine(targetdirPath, exeName), "");
            Msg("注册表修改是否成功:" + result, targetdirPath);
        }
        /// <summary>
        /// 卸载完成之后触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       public static void InstallerDemo_AfterUninstall(string keyName,string targetPaht)
        {
            //throw new NotImplementedException();
            Msg("注册表信息删除开始:", targetPaht);
            var result = RegeditDelete(keyName, targetPaht);
            Msg("注册表信息删除:" + result, targetPaht);
        }
        /// <summary>
        /// 注册协议
        /// </summary>
        /// <param name="Root_Key">根节点</param>
        /// <param name="file_application_path">应用程序路径</param>
        /// <param name="file_application_ico">应用程序打开图标,可选值</param>
        /// <returns></returns>
       public static bool RegeditAdd(string Root_Key, string file_application_path, string file_application_ico)
        {            
            RegistryKey reg_ClassRoot = Registry.ClassesRoot;
            string targetdirPath="";
            try
            {
                targetdirPath = System.IO.Path.GetDirectoryName(file_application_path);
                RegistryKey reg_key = reg_ClassRoot.OpenSubKey(Root_Key, true);
                if (reg_key == null)
                {
                    //创建子节点HKEY_CLASSES_ROOT\tpswftest
                    RegistryKey reg_sjbs = reg_ClassRoot.CreateSubKey(Root_Key);
                    //添加默认项
                    reg_sjbs.SetValue("", "URL: " + Root_Key + " Protocol Handler");
                    //协议别名
                    reg_sjbs.SetValue("URL Protocol", file_application_path);
                    //创建[HKEY_CLASSES_ROOT\tpswftest\DefaultIcon]
                    RegistryKey reg_DefaultIcon = reg_sjbs.CreateSubKey("DefaultIcon");
                    if (!String.IsNullOrEmpty(file_application_ico))
                    {
                        //设置自定义图标
                        reg_DefaultIcon.SetValue("", file_application_ico);
                    }
                    else
                    {
                        //设置系统定义图标
                        reg_DefaultIcon.SetValue("", file_application_path + ",1");
                    }
                    //创建呼出处理程序[HKEY_CLASSES_ROOT\tpswftest\shell\open\command]
                    RegistryKey reg_command = reg_sjbs.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command");
                    //%1 表示传递的参数,再次%1表示调用处显示链接文本
                    reg_command.SetValue("", "\"" + file_application_path + "\" \"%1\"");
                }
                return true;
            }
            catch (Exception ex)
            {
                Msg(ex.Message.ToString(), targetdirPath);
                return false;
            }
            finally { reg_ClassRoot.Close(); }
        }

        /// <summary>
        /// 删除协议
        /// </summary>
        /// <param name="Root_Key">根节点</param>
        /// <returns></returns>
       public static bool RegeditDelete(string Root_Key,string targetPaht)
        {
            //获取注册表HKEY_CLASSES_ROOT
            RegistryKey reg_ClassRoot = Registry.ClassesRoot;
            try
            {
                //获取注册表[HKEY_CLASSES_ROOT\tpswftest]项
                RegistryKey reg_sjbs = reg_ClassRoot.OpenSubKey(Root_Key, true);
                if (reg_sjbs != null)
                {
                    reg_ClassRoot.DeleteSubKeyTree(Root_Key);
                    return true;
                }
                else
                {
                    //Msg("注册表中" + reg_ClassRoot + "\\" + Root_Key + "不存在!", "");
                    return false;
                }

            }
            catch (Exception ex)
            {
                //添加错误日志
                Msg(ex.Message.ToString(), "");
                return false;
            }
            finally { reg_ClassRoot.Close(); }
        }
        /// <summary>
        /// 日志
        /// </summary>
        /// <param name="message"></param>
       public static void Msg(string message,string targetdirPath)
        {
            string rootPath = targetdirPath;
            if (string.IsNullOrEmpty(rootPath))
            {
                rootPath = "D:\\runsoft\\meswfTest";
            }
            try
            {
                
                Console.WriteLine(message);
            }
            catch (Exception _exception)
            {
                throw;
            }
        }
    }
}

3、文件上传后台程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace UpDownLoadFileServer
{
    /// <summary>
    /// 文件上传服务端zhanghaifeng20181025
    /// </summary>
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (string f in Request.Files.AllKeys)
            {
                try
                {
                    HttpPostedFile file = Request.Files[f];
                    string relativePath = Request.QueryString["relativePath"];
                    string webSiteName = Request.QueryString["webSiteName"];
                    //webSiteName = "jixunzhongxinCesium/cloud/";
                    string serverLocalFilePath = Server.MapPath("../" + webSiteName + "/" + relativePath);
                    string filePathName = Path.GetDirectoryName(serverLocalFilePath);
                    Directory.CreateDirectory(filePathName);
                    file.SaveAs(serverLocalFilePath);
                    SaveThumb(serverLocalFilePath);
                }
                catch (Exception)
                {

                }
            }
        }

        public static void SaveThumb(string serverLocalFilePath)
        {
            try
            {
                string newPath = serverLocalFilePath.Replace("缺陷数据", "缺陷数据缩略图").Replace("原始数据", "原始数据缩略图");
                string filePathName = Path.GetDirectoryName(newPath);
                Directory.CreateDirectory(filePathName);
                WebImgUtil.ImageUtil.MakeThumbnail(serverLocalFilePath, newPath, 500, 500, "HW");
            }
            catch (Exception)
            {
            }

        }
    }
}

4、前端页面功能入口

<div id="uploadpanel" class="easyui-window" title="数据传输" data-options="closable:true,collapsible:false,minimizable:false,closed:true" style="width:300px;height:180px; padding-top: 30px">
        <div style="text-align: center">
            <button id="btnloaduploadexe">程序注册</button>
            <p></p>
            <a id="aupload" style="font-size: 14px" href="yupontuploadapp://host_db_user_pass_images_aspx">
                启动程序
            </a>
            <p></p>
            <p></p>
            <p>说明:第一次使用上传下载程序需要先注册</p>
        </div>
    </div>

猜你喜欢

转载自www.cnblogs.com/dog2016/p/9929248.html