文件上传下载(C#,web,asp.net)
目的:在浏览器页面启动上传下载CS软件,实现文件的批量下载与上传。
技术路线:
开发上传下载客户端CS程序与注册程序,压缩放到服务器端指定位置;
开发服务器端程序用以接收上传请求,压缩放到服务器端;
将数据服务端程序与客户端程序压缩包用IIS发布
开发前端页面,提供下载上传下载程序压缩包的功能,提供打开上传下载程序的功能;
内容:
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<)
{
return;
}
ParseExePara(args);
App app = new App();
app.InitializeComponent();
app.Run();
return;
} public static void ParseExePara(string[] args)
{
if (args.Length<)
{
return;
}
string paraRemoved = "yupontuploadapp://";
string para = args[];
para = para.Replace(paraRemoved, "").Trim();
if (!string.IsNullOrWhiteSpace(para)&¶.Length>)
{
string[] allParas=para.Split('_');
if (allParas.Length<)
{
return;
}
YpGlobalWPF.CommonUtil.Para = new CommonUtils.MySqlConnPara()
{
Host = allParas[],
DataBase = allParas[],
UserName = allParas[],
Password = allParas[]
};
if (allParas.Length>)
{
YpGlobalWPF.CommonUtil.CesiumDataBaseUrl = allParas[];
string upLoadFilePathRelative;
if (allParas[].Contains("127.0.0.1"))
{
upLoadFilePathRelative = YBCommonUtility.StringUtility.GetAfterRemovePreStr(allParas[], "127.0.0.1");
}
else if (allParas[].Contains("localhost"))
{
upLoadFilePathRelative = YBCommonUtility.StringUtility.GetAfterRemovePreStr(allParas[], "localhost");
}
else
{
upLoadFilePathRelative = YBCommonUtility.StringUtility.GetAfterRemovePreStr(allParas[], YpGlobalWPF.CommonUtil.Para.Host);
}
YpGlobalWPF.CommonUtil.UpLoadDataDirRelative = upLoadFilePathRelative;
YpGlobalWPF.CommonUtil.SourceFilePath = allParas[]+"/images/原始数据";
YpGlobalWPF.CommonUtil.FaultFilePath = allParas[] + "/images/缺陷数据";
}
if (allParas.Length>)
{
YpGlobalWPF.CommonUtil.ServerAspx = allParas[];
}
}
}
}
}
//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 == )
{
CommonUtil.ShowMessage("提示", "没找到照片!");
return false;
}
frmPictureTreeDownFile.Instance.picTree.DataContext = picTreeViewModel; List<NameValueItem> cmbLineSource = picTreeViewModel.GetCmbLines();
cmbLineSource.Insert(,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(, new NameValueItem("全部", "全部"));
frmPictureTreeDownFile.Instance.cmbPoles.ItemsSource = cmbPoleSource;
if (poleName==null)
{
frmPictureTreeDownFile.Instance.cmbPoles.SelectedIndex = ;
return;
}
else
{
if (cmbPoleSource.Count>)
{
if (cmbPoleSource[].Value.ToString().EndsWith("#"))
{
poleName = poleName.Replace("号", "#");
if (!poleName.EndsWith("#"))
{
poleName += "#";
}
}
if (cmbPoleSource[].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[].Children.Count == )
{
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==)
{
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 = ;
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>)
{
this.cmbDataType.SelectedIndex = ;
}
if (cmbDataType.SelectedIndex == )
{
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 > )
{
this.cmbDataLevel.SelectedIndex = ;
}
this.cmbDataType.SelectionChanged += (s, e) =>
{
if (cmbDataType.SelectedIndex==)
{
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>)
{
this.cmbDataLevel.SelectedIndex = ;
}
};
} 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 = ;
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>)
{
if(_AllLog[_removeRecordIndex].Message.Contains("失败"))
{
_AllLog.RemoveAt(_removeRecordIndex);
}
else
{
if (_removeRecordIndex<_AllLog.Count-)
{
_removeRecordIndex++;
}
}
}
if (_AllLog.Count>)
{
_AllLog.RemoveAt();
}
_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 * ) / TotalCount, );
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 = ;
}
else if (type.Equals(Model.enumDataType.缺陷数据.ToString()))
{
this.cmbDataType.SelectedIndex = ;
}
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, , , "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>
文件上传下载(C#,web,asp.net)的更多相关文章
- WEB文件上传下载功能
WEB文件上传下载在日常工作中经常用到的功能 这里用到JS库 http://files.cnblogs.com/meilibao/ajaxupload.3.5.js 上传代码段(HTML) <% ...
- JAVA Web 之 struts2文件上传下载演示(二)(转)
JAVA Web 之 struts2文件上传下载演示(二) 一.文件上传演示 详细查看本人的另一篇博客 http://titanseason.iteye.com/blog/1489397 二.文件下载 ...
- JAVA Web 之 struts2文件上传下载演示(一)(转)
JAVA Web 之 struts2文件上传下载演示(一) 一.文件上传演示 1.需要的jar包 大多数的jar包都是struts里面的,大家把jar包直接复制到WebContent/WEB-INF/ ...
- java web 文件上传下载
文件上传下载案例: 首先是此案例工程的目录结构:
- SpringMVC整合fastdfs-client-java实现web文件上传下载
原文:http://blog.csdn.net/wlwlwlwl015/article/details/52682153 本篇blog主要记录一下SpringMVC整合FastDFS的Java客户端实 ...
- iOS开发之结合asp.net webservice实现文件上传下载
iOS开发中会经常用到文件上传下载的功能,这篇文件将介绍一下使用asp.net webservice实现文件上传下载. 首先,让我们看下文件下载. 这里我们下载cnblogs上的一个zip文件.使用N ...
- SpringMVC文件上传下载
在Spring MVC的基础框架搭建起来后,我们测试了spring mvc中的返回值类型,如果你还没有搭建好springmvc的架构请参考博文->http://www.cnblogs.com/q ...
- JavaWeb实现文件上传下载功能实例解析
转:http://www.cnblogs.com/xdp-gacl/p/4200090.html JavaWeb实现文件上传下载功能实例解析 在Web应用系统开发中,文件上传和下载功能是非常常用的功能 ...
- WebService实现文件上传下载
一:服务端:一个普通java web工程 package com.wzh.file; import com.sun.xml.ws.developer.StreamingAttachment; impo ...
随机推荐
- spring boot 集成 rabbitmq
1.使用默认的AmqpTemplate生产消费pojo时,pojo需要implement Serializable,否则会抛出org.springframework.amqp.AmqpExceptio ...
- Py修行路 python基础 (十)装饰器
装饰器 一.定义 装饰器:顾名思义,就是对某个东西起到装饰修饰的功能. python中的装饰器,其本质上就是一个python函数,它可以让其他函数在不需要任何代码变动的前提下增加额外功能.通俗理解就是 ...
- oracle:RETURNING 子句
RETURNING 自己通常结合DML 语句使用.(INSERT UPDATE DELETE) 使用方法: UPDATE table_name SET expr1 RETURNING column_n ...
- The centos disc was not found in any of your drives.Please insert the centos disc and press OK to retry
查看虚拟机设置中关于CDROM的选项,将CDROM的状态改为已连接,不要奇怪,勾选上之后再按下OK就好了
- C语言之随机数和字符串输入输出
一.随机数产生函数 1.需要加入头文件 #include<stdlib.h> 和 #include<time.h> 2.Rand是伪随机数产生器,每次调用rand产生的随机数是 ...
- Linux的基本指令--
VIM简介: Vi有三种基本工作模式 1.命令模式 2.文本输入模式 3. 末行模式 VIM基本操作: 一 . 进入插入模式: i: 插入光标前一个字符 I: 插入行首 a: 插入光标后一个字符 A ...
- sublime添加右键菜单
参考:https://www.zhihu.com/question/29662273/answer/45277925 @echo Off :START CLS echo *============== ...
- java Web 过滤器Filter详解
简介 Filter也称之为过滤器,Web开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或静态 html 文件等进行拦截,从而实现一些特殊 ...
- 使用laravel实现用户的登陆
首先在 php artisan 里面 make:auth 生产一个门脸类 修改配置文件里面要哪个模型登陆 模型得继承一下才能 先写一下注册 密码必须要使用laravel的加密方法,使用MD5都没用 l ...
- SpringBoot24 SpringDataJPA环境搭建、实体类注解、关联查询
1 版本说明 JDK:1.8 MAVEN:3.5 SpringBoot:2.0.4 IDEA:旗舰版207.2 MySQL:5.5 2 SpringDataJPA环境搭建(SpringBoot版本) ...