zoukankan      html  css  js  c++  java
  • webservice上传图片

            public string servicepath = "";
            public StringBuilder pathstr = new StringBuilder();
            private void btnExplo_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    textImagePath.Text = openFileDialog1.FileName;
                }
            }
    
            private void btnUpPic_Click(object sender, EventArgs e)
            {
                string name = CommonClass.FileManage.GenerateId();
                string filepath = textImagePath.Text;
    
                if (File.Exists(filepath))
                {
                    if (CommonClass.FileManage.CheckImgFormat(@filepath))
                    {
                        FileInfo fileInfo = new FileInfo(filepath);
                        if (fileInfo.Length < 3145728)
                        {
                            BackGroundManage.ServiceReference1.SecurityHeader header = new BackGroundManage.ServiceReference1.SecurityHeader();
                            header.SecurityKey = CommonClass.XmlManage.ReadConNode("upload", "SecurityKey");
                            BackGroundManage.ServiceReference1.UpDownServiceSoapClient up = new BackGroundManage.ServiceReference1.UpDownServiceSoapClient();
    
                            pathstr.Append(servicepath);
                            pathstr.Append(DateTime.Now.Year.ToString());
                            if (DateTime.Now.Month < 10)
                            {
                                pathstr.Append("0");
                            }
                            pathstr.Append(DateTime.Now.Month.ToString());
                            pathstr.Append("\\");
                            if (DateTime.Now.Day < 10)
                            {
                                pathstr.Append("0");
                            }
                            pathstr.Append(DateTime.Now.Day.ToString());
                            pathstr.Append("_");
                            pathstr.Append(name);
                            pathstr.Append(".");
                            pathstr.Append(filepath.Substring(filepath.LastIndexOf('.') + 1));
    
                            //数据库保存时名称为"Images"+"\\"+"pathstr.ToString()
    
                            bool upf = up.Up(header, CommonClass.FileManage.FileToByte(@filepath), pathstr.ToString());
                            if (upf)
                            {
                                MessageBox.Show("成功");
                            }
                            else
                            {
                                MessageBox.Show("失败");
                            }
                        }
                        else
                        {
                            MessageBox.Show("上传图片大小超过限制!\n只允许小于3M的文件!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show("上传图片格式不正确!\n只允许上传.gif/.jpg/.png的文件!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("文件不存在\n请重新选择文件!!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    
                }
            }
    
  • 相关阅读:
    let和const====均参考阮大神的es6入门
    面向对象封装
    记忆函数
    PHP面试题一[转]
    TDSSNIClient 初始化失败,出现错误 0x7e,状态代码 0x60。
    针对hasp加密狗服务器客户机ip不在同一个网段的解决方案
    sql 语句用isnull函数的用法
    如何用JS获取键盘上任意按键的值?兼容FireFox和IE js获取键盘ASCII码?js键盘事件全面控制
    adobe captivate 5.5 中文教程
    档案软件演示版下载安装说明书
  • 原文地址:https://www.cnblogs.com/feathers/p/2103175.html
Copyright © 2011-2022 走看看