winform上传文件
//上传图片 文件
public int addUpPic( String strProCode,String strFileName,String strUpType)
{
//strFileName 旧路径
String strPicName = Path.GetFileName(strFileName);
//// new BasicClass().splitFileName(strFileName);
//新路径
String path = "";
//备份文件夹
String backPath = "";
if (strUpType == "文件")
{
path = new DateBasicInfo.ConDb().getParamter()[3] + @"\" + strPicName;
backPath = new DateBasicInfo.ConDb().getParamter()[4];
}
else if (strUpType == "图纸")
{
path = new DateBasicInfo.ConDb().getParamter()[6] + @"\" + strPicName;
backPath = new DateBasicInfo.ConDb().getParamter()[7];
}
else if (strUpType == "样品")
{
path = new DateBasicInfo.ConDb().getParamter()[8] + @"\" + strPicName;
backPath = new DateBasicInfo.ConDb().getParamter()[9];
}
else {
//图片
path = new DateBasicInfo.ConDb().getParamter()[1] + @"\" + strPicName;
backPath = new DateBasicInfo.ConDb().getParamter()[2];
}
//备份文件名
String backFileName=getFile( backPath,strFileName);
try
{
try
{
if (File.Exists(path))
{
//如果已经上传过,将上次上传的文件复制到proImageBack 文件夹下
File.Copy(path, backFileName, true);
}
}catch(Exception ee)
{
System.Windows.Forms.MessageBox.Show("不存在文件"+path);
return 0;
}
//上传文件
File.Copy(strFileName.Trim(), path, true);
SqlParameter[] parms ={
new SqlParameter("@pro_code",strProCode),
new SqlParameter("@assistantName",strPicName),
new SqlParameter("@flag","1"),
new SqlParameter("@upType",strUpType),
new SqlParameter("@upMan",DateBasicInfo.userMessage.userName)
};
return DateBasicInfo.ConDb.ExecProc("addUpProAssistant", parms);
}
catch (Exception ex)
{
return 0;
}
}
// System.Diagnostics.Process.Start(strFilePath); 打开文件
/////下载
private void btnDownload_Click(object sender, EventArgs e)
{
String strUpType = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "anType").ToString();
String strFile = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "annexName").ToString();
String strFilePath = "";
if (strUpType == "图片")
{
strFilePath = new DateBasicInfo.ConDb().getParamter()[1] + @"" + strFile;
}
else if (strUpType == "图纸")
{
strFilePath = new DateBasicInfo.ConDb().getParamter()[6] + @"" + strFile;
}
else if (strUpType == "样品")
{
strFilePath = new DateBasicInfo.ConDb().getParamter()[8] + @"\" + strFile;
}
else
{
strFilePath = new DateBasicInfo.ConDb().getParamter()[3] + @"\" + strFile;
}
#region 本地文件拷贝
//OpenFileDialog filedlg = new OpenFileDialog();
//filedlg.Multiselect = false;
//string strFilePath="";
//if (filedlg.ShowDialog() == DialogResult.OK)
//{
// strFilePath = filedlg.FileName;
//}
//else
//{
// return;
//}
#endregion
FileStream fs = new FileStream(strFilePath, FileMode.Open, FileAccess.Read);
byte[] bt = new byte[fs.Length];
fs.Position = 0;
fs.Read(bt, 0, Convert.ToInt32(fs.Length));
fs.Close();
FolderBrowserDialog fld = new FolderBrowserDialog();
if (fld.ShowDialog() == DialogResult.OK)
{
try
{
string path = fld.SelectedPath;
if (!path.EndsWith(@"\"))//判斷是否為根目錄,如果不是根目錄要添加分隔符"\"
path += @"\";
byte[] btFile = bt;
int ind=strFilePath.LastIndexOf('\\')+1;
FileStream fss = new FileStream(path + strFilePath.Substring(ind, strFilePath.Length - ind), FileMode.Create);
fss.Write(btFile, 0, btFile.Length);
fss.Close();
}
finally
{
}
}
}
winform上传文件的更多相关文章
- winform 上传文件
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...
- WinForm上传文件,下载文件
上传文件: 使用OpenFileDialog控件选择文件, 具体代码示例: private void btnUpLoadPic_Click(object sender, EventArgs e) { ...
- winform上传文件,利用http,form-data格式上传
/// <summary> /// 上传文件 /// </summary> /// <param name="url">服务地址</par ...
- C# winform 上传文件到服务器
1.首先要在服务器端新建一个网站axpx页 然后再网站的后台写代码获取winform传过来的文件名. 声明:这个方法虽然最简单最省事,但是上传大文件可能会报错,我的机器是10M, 超过10M就会提示报 ...
- winform上传文件到服务器——资料整理
标题:使用简单的wcf文件实现上传,下载文件到服务器 地址:https://blog.csdn.net/duanzi_peng/article/details/19037777
- c# Winform上传文件
http://blog.csdn.net/shihuan10430049/article/details/3734398这个代码有点问题 http://blogs.msdn.com/b/johan/a ...
- 客户端(Winform窗体)上传文件到服务器(web窗体)简单例子
客户端:先创建一个winform窗体的应用程序项目 项目结构
- Winform上传下载文件代码
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...
- C#在WinForm下使用HttpWebRequest上传文件
转自:http://blog.csdn.net/shihuan10430049/article/details/3734398 这段时间因项目需要,要实现WinForm下的文件上传,个人觉得采用FTP ...
随机推荐
- android 豆瓣客户端 视频
链接如下:http://download.csdn.net/detail/jltxgcy/5667337
- Cocos2d-x 截图功能
2.x-3.x版本 //获取屏幕尺寸 CCSize size = CCDirector::sharedDirector()->getWinSize ...
- javascript实现 京东淘宝等商城的商品图片大图预览功能
在京东和淘宝等购买东西的时候,我们会经常预览左侧商品展示图片,把鼠标放到原图,右侧就会有个大图显示出细节.本文将带领大家写一个这样简单的功能! 一.实现原理 当鼠标移入某一图片内部时,图片上部会出现一 ...
- testlink用例转换小工具(excel转为xml,python版)
前面文章记录了testlink的安装方法(CentOS 7下安装xampp和testlink),由于testlink仅支持xml格式的用例导入,研究了下excel转xml的方法, 从网上其他网友那里借 ...
- C++继承、多态、虚函数
#答案:http://www.cnblogs.com/tinaluo/articles/6290994.html 1 编写程序:定义一个抽象基类sharpe,只有包含一个求面积的纯虚函数,派生出矩形类 ...
- 微信公众平台开发之基于百度 BAE3.0 的开发环境搭建(MyEclipse + SVN)
等待加载完成后,在"Personal Sites" 栏目中会显示你加载的SVN的相关内容,展开"SVN"分别选择"Core SVNKit Librar ...
- node.JS中配置http-server
http-server 是一个简单的HTTP服务器, 基于 nodeJs,在nodejs命令行中配置http服务器. 项目结构:
- package com.sun.image.codec.jpeg does not exist
rt.jar 是sun公司内部使用的包,不建议外部使用,rt.jar是被用了的,但是里面的com.sun下面的包不被默认加载了, JAVA7之前是默认加载的,所有用JAVA7以前的JDK编译是通过的. ...
- 常见IT面试题
1.爬楼梯问题,有个N阶的楼梯,一个人可以一次爬1阶,也可以爬2阶,求问总计有多少种爬法? F(N)= F(N-1)+F(N-2). N=1时,有1种爬法,N=2时,有2种爬法.该题可以用递归方法求解 ...
- InnoDB与MyISAM引擎区别
mysql中InnoDB与MyISAM两种数据库引擎的区别: 一.InnoDB引擎: 1.支持事务性, 2.支持外部键, 3.行级锁, 4.不保存表的具体行数,执行select count(*) fr ...