• 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);
    
                }
            }
    
  • 相关阅读:
    Java 集合类
    Java 中的四种引用及垃圾回收策略
    Java 类的加载过程(阿里面试题)
    JMeter进行一次简单的压力测试
    python使用 HTMLTestRunner.py生成测试报告
    python读取配置文件
    python的IDE工具-- Pycharm
    selenium webdriver+python基本操作
    SQL开发测试使用基础
    python学习笔记
  • 原文地址:https://www.cnblogs.com/feathers/p/2103175.html
Copyright © 2020-2023  润新知