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);
    
                }
            }
    
  • 相关阅读:
    Angular vs. React vs. Vue
    探索Virtual DOM的前世今生
    GRPC 负载均衡
    揭秘!用标准Go语言能写脚本吗?
    grpc 连接 复用 在 Go 中发现竞态条件 (Race Conditions)
    读取网络包
    User Datagram Protocol
    注册表项 DeviceInstance
    gopacket 抓包 过滤器
    Mysql 通信协议抓包分析
  • 原文地址:https://www.cnblogs.com/feathers/p/2103175.html
Copyright © 2011-2022 走看看