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 ...
随机推荐
- 谈谈new Thread的弊端及Java四种线程池的使用
1.new Thread的弊端执行一个异步任务你还只是如下new Thread吗? new Thread(new Runnable() { @Override public void run() { ...
- Android- assent和raw的区别
Android- assent和raw的区别 相同点: 里面的文件在编译的时候都不会被编译成二进制文件,都会原封不动的打包. 不同点: 1.存放的路径不一样,一般assets存放在项目的根目录下,而r ...
- 向python3进发
在Python2.x中,交互输入有input和raw_input两种方法 input-----------tmd是个坑,就别用 raw_input------把输入无论是Int或str都当做是str处 ...
- ES 6 : 函数的扩展
1. 函数参数的默认值 [ 基本用法 ] 在ES6之前,不能直接为函数的参数指定默认值,只能采用变通的方法. 上面的代码检查函数log的参数y有没有赋值,如果没有,则指定默认值为world.这种写法的 ...
- http缓存与cdn相关技术
阅读目录 一 http缓存 二.Http缓存概念解析 三.cdn相关技术 摘要:最近要做这个主题的组内分享,所以准备了一个星期,查了比较多的资料.准备的过程虽然很烦很耗时间,不过因为需要查很多的资料, ...
- C# 实验4 数据库
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 一步步优化JVM四:决定Java堆的大小以及内存占用
到目前为止,还没有做明确的优化工作.只是做了初始化选择工作,比如说:JVM部署模型.JVM运行环境.收集哪些垃圾回收器的信息以及需要遵守垃圾回收原则.这一步将介绍如何评估应用需要的内存大小以及Java ...
- MATLAB初体验
好激动 要入MATLAB的大坑了 恩 很遗憾第一个程序并不是hello world 好 插入代码里并没有MATLAB这个选项 这是一种歧视 x=[:pi/:*pi]; y=sin(x); plot(x ...
- CodeForces 710A King Moves
简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...
- 1.webpack-----模块加载器兼打包工具
一.webpack的优势 1. 能模块化 JS . 2. 开发便捷,能替代部分 grunt/gulp 的工作,比如打包.压缩混淆.图片转base64等. 3. 扩展性强,插件机制完善,特别是支持 Re ...