//上传图片 文件

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. iOS之上架打包时报错:ERROR ITMS-90086: "Missing 64-bit support.

    根据错误信息在网上基本找到的解决方法是设置targets中build settings中的architectures中的内容 这是因为现在提交的app必须支持64位.  

  2. MongoDB应用案例:使用 MongoDB 存储日志数据

    线上运行的服务会产生大量的运行及访问日志,日志里会包含一些错误.警告.及用户行为等信息,通常服务会以文本的形式记录日志信息,这样可读性强,方便于日常定位问题,但当产生大量的日志之后,要想从大量日志里挖 ...

  3. [Angular Directive] Implement Structural Directive Data Binding with Context in Angular

    Just like in *ngFor, you're able to pass in data into your own structural directives. This is done b ...

  4. Apache2.2下载及安装

    php5.5 + apache2.4 安装配置图文步骤 http://wenku.baidu.com/link?url=8OHaJATVBHP5QrD-J2pTkmBOjY-ZG5cDngKMz7wl ...

  5. 第一百二十九节,JavaScript,理解JavaScript库

    JavaScript,理解JavaScript库 学习要点: 1.项目介绍 2.理解JavaScript库 3.创建基础库 从本章,我们来用之前的基础知识来写一个项目,用以巩固之前所学.那么,每个项目 ...

  6. Attribute value is quoted with " which must be escaped when used within the value 问题解决

    访问JSP时,报错:Attribute value is quoted with " which must be escaped when used within the value .相信 ...

  7. LeetCode 392. Is Subsequence

    Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...

  8. [MFC美化] SkinMagic使用详解3- 常见使用问题解答

    在SkinMagic使用过程中,经常遇到以下几个问题: 1. 静态加载皮肤文件时,资源文件IDR_SKIN_CORONA可能会报错:未声明的标识符 解决方法:添加头文件"Resource.h ...

  9. mysql 查看数据库中所有表的记录数

    use information_schema; SELECT DISTINCT t.table_name, t.engine '表引擎', t.table_rowsFROM TABLES tWHERE ...

  10. [学习笔记]agileone安装登陆报错,localhost重定向次数过多

    1.找到.htaccess文件 2.修改RewriteEngine  参数为off即可