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);
    
                }
            }
    
  • 相关阅读:
    MongoDB Java连接---MongoDB基础用法(四)
    MongoDB用户,角色管理 --- MongoDB基础用法(三)
    Mongodb命令 --- MongoDB基础用法(二)
    MongoDB简介---MongoDB基础用法(一)
    Docker 私有仓库
    Dockerfile
    Docker部署Mysql, Tomcat, Nginx, Redis
    Docker 容器的数据卷
    封装的多功能多效果的RecyclerView
    安卓实现沉浸式效果,状态栏变色
  • 原文地址:https://www.cnblogs.com/feathers/p/2103175.html
Copyright © 2011-2022 走看看