//上传图片 文件

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
{ }
} }

最新文章

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

热门文章

  1. 链方法[C# 基础知识系列]专题三:如何用委托包装多个方法——委托链
  2. php+redis实现多台服务器内网存储session并读取
  3. 搞定单模式匹配(简单,KMP)
  4. 分享php工作中遇到的一些探究和技巧【2】
  5. ssm框架中css被拦截
  6. SR-IOV简介
  7. 抓包分析SIP消息
  8. [UWP-小白日记13]Composition动画
  9. 有哪些可以将网页另存图片的chrome插件?功能类似网页截图
  10. Python机器学习包