//上传图片 文件

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上传文件的更多相关文章

  1. winform 上传文件

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  2. WinForm上传文件,下载文件

    上传文件: 使用OpenFileDialog控件选择文件, 具体代码示例: private void btnUpLoadPic_Click(object sender, EventArgs e) { ...

  3. winform上传文件,利用http,form-data格式上传

    /// <summary> /// 上传文件 /// </summary> /// <param name="url">服务地址</par ...

  4. C# winform 上传文件到服务器

    1.首先要在服务器端新建一个网站axpx页 然后再网站的后台写代码获取winform传过来的文件名. 声明:这个方法虽然最简单最省事,但是上传大文件可能会报错,我的机器是10M, 超过10M就会提示报 ...

  5. winform上传文件到服务器——资料整理

    标题:使用简单的wcf文件实现上传,下载文件到服务器 地址:https://blog.csdn.net/duanzi_peng/article/details/19037777

  6. c# Winform上传文件

    http://blog.csdn.net/shihuan10430049/article/details/3734398这个代码有点问题 http://blogs.msdn.com/b/johan/a ...

  7. 客户端(Winform窗体)上传文件到服务器(web窗体)简单例子

    客户端:先创建一个winform窗体的应用程序项目 项目结构

  8. Winform上传下载文件代码

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  9. C#在WinForm下使用HttpWebRequest上传文件

    转自:http://blog.csdn.net/shihuan10430049/article/details/3734398 这段时间因项目需要,要实现WinForm下的文件上传,个人觉得采用FTP ...

随机推荐

  1. webpack中加载CSS

    webpack强大之处在于可以将CSS当做一个资源模块进行管理和加载 基本使用: 安装webpack的加载插件style-loader和css-loader: npm install style-lo ...

  2. Flexible 弹性盒子模型之CSS align-items 属性

    实例 居中对齐弹性盒的各项 <div> 元素: div { display: flex; align-items:center; } 复制 效果预览 浏览器支持 表格中的数字表示支持该属性 ...

  3. 【C#】Get the html code of a webpage

    As for the title,the console program will show you a sample which can get the webpage-code.Enjoy it: ...

  4. Date类型常用概念及方法总结(1)

      Date类型使用UTC(国际协调时间)1970年1月1日零时开始经过的毫秒数来保存时间. (1)创建当前日期           调用Date不传递参数的情况下,创建的新对象自动获得当前日期和时间 ...

  5. arcengine 开发经典帖

    http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=25575&page=1&extra= 使用ArcGIS Engine 开发自定义 ...

  6. [CSS3备忘] transform animation 等

    一些CSS不经常用就会忘记,好吧,现在整理再学习一下,也留做备忘,方便以后查看... perspective的理解: 1.数值越小,用户与3D空间Z平面距离越近,视觉效果更令人印象深刻(比如看电影,越 ...

  7. asp.net小技巧:保留password模式文本框textbox内的数据不丢失。

    在asp.net 2.0环境下,使用textbox,提交到服务器再传回,如果textbox是password模式的,那么textbox内的密码(星号.圆点),就没有了! 一个可行的做法是 : prot ...

  8. windows Git安装

    git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目 一.Git下载 官网地址:https://git-scm.com/download/win,选择相应的版本即可 二.安 ...

  9. 读取Oracle表结构数据

    <html lang="zh-cn"> <head> <meta name="generator" content="O ...

  10. 负载均衡,最理想使用 redis实现session共享

    负载均衡在多台php服务器负载均衡的情况下,第一秒请求是a服务器,第二秒请求是b服务器, session必须放在一个公共的服务器,最理想是使用 redis实现session共享.内存的速度比磁盘访问快 ...