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
{
}
}
}
最新文章
- javascript的变量作用域--对比js、php和c的for循环
- mysql判断一个字符串是否包含某子串
- XMPP框架下微信项目总结(1)环境配置
- PHP--Warning: Invalid argument supplied for foreach() in ...
- Python异常记录
- GNU工具链学习笔记
- (原)python中matplotlib的颜色及线条控制
- 将主机IDS OSSEC日志文件存入MYSQL的方法
- laravel框架一种方便的快速填充数据的方法
- Java日志框架:slf4j作用及其实现原理
- 【转】Java方向如何准备技术面试答案(汇总版)
- [LeetCode] Quad Tree Intersection 四叉树相交
- 转载 [c#] 虚函数(Virtual),抽象函数(abstract)和接口的区别
- C#网络编程之进程管理
- python爬虫训练——爬poj题目
- NOIP2018复赛获奖名单
- 中国移动CMPP协议、联通SGIP协议、电信SMGP协议短信网关
- stm32f103串口实现映射功能
- 基于PU-Learning的恶意URL检测
- 一些常用的基础Linux操作指令