资源简介

webservice的上传、下载、获取文件名称数量,完整代码 可直接运行

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            //1先要发布webservice然后部署在iis中 或者将webservice工程单独打开启动
            //2在引用中添加服务引用  发布后或者启动的地址 
            //3如果第2步的引用调用不到webservice的方法 重新引用 在引用右键添加服务引用 不输入地址,左下角点击“高级“弹出的窗体中左下角点击“添加web引用“ 在弹出的窗体中输入webservice的地址即可
            //4就可以调用webservice方法了
            string path = string.Empty;//返回上传时的完整路径    可截取保存文件名
            SaveImg(“222“ out path);
        }
        /// 
        /// 保存图片
        /// 

        /// 服务器文件夹名
        /// 全路径
        /// 
        public string SaveImg(string MouldName out string path)
        {
            string fileName = string.Empty;
            OpenFileDialog ofd = new OpenFileDialog();//选择文件的窗体
            ofd.Filter = “JPG文件|*.jpg|PNG文件|*.png“;//限制文件类型如果不限制注释即可
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                localhost.WebService1 web = new localhost.WebService1();//引用webservice
                byte[] fs = File.ReadAllBytes(ofd.FileName);
                int index = ofd.FileName.LastIndexOf(“\\“) + 1;
                fileName = ofd.FileName.Substring(index);
                //pb.Tag = fileName;
                path = ofd.FileName;//返回上传时的完整路径          
                //上传文件
                string str = web.UploadFile(““ MouldName fileName fs);//调用webservice的方法
                path = ofd.FileName;
                if (str != ““)
                {
                    MessageBox.Show(str);
                }
            }
            else
            {
                path = null;
            }
            return fileName;
        }

        private void button2_Click(object sender EventArgs e)
        {
            OpenImg(“222“ “56ea133427366.jpg“);
        }
        /// 
        /// 下载文件
        /// 

        /// 
        /// 
        public void OpenImg(string MouldName string fileName)
        {
            localhost.WebService1 web = new localhost.WebService1();//引用webservice
            byte[] file = web.DownloadFile(““MouldName fileName);
            SaveFileDialog sfd = new SaveFileDialog();
            //sfd.Filter = “EXCEL文件(*.xlsx)|*.xlsx“;
            List lTemp = new List();
            lTemp.AddRange(file);
            lTemp.RemoveRange(0 10);
            byte[] fileS = new byte[lTemp.Count];
            l

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-10-21 17:17  webservice文件上传下载\
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\.vs\
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\.vs\WindowsFormsApplication1\
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\.vs\WindowsFormsApplication1\v14\
     文件        5120  2019-10-21 17:16  webservice文件上传下载\demo\WindowsFormsApplication1\.vs\WindowsFormsApplication1\v14\.suo
     文件        1046  2019-10-21 16:59  webservice文件上传下载\demo\WindowsFormsApplication1\App.config
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\bin\
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\bin\Debug\
     文件       20992  2019-10-21 17:13  webservice文件上传下载\demo\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
     文件        1046  2019-10-21 16:59  webservice文件上传下载\demo\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe.config
     文件       40448  2019-10-21 17:13  webservice文件上传下载\demo\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
     文件       22696  2019-10-21 17:16  webservice文件上传下载\demo\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
     文件        1046  2019-10-21 16:59  webservice文件上传下载\demo\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.config
     文件         490  2018-04-12 07:35  webservice文件上传下载\demo\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
     文件        4966  2019-10-21 17:13  webservice文件上传下载\demo\WindowsFormsApplication1\Form1.cs
     文件        3301  2019-10-21 17:07  webservice文件上传下载\demo\WindowsFormsApplication1\Form1.Designer.cs
     文件        5817  2019-10-21 17:07  webservice文件上传下载\demo\WindowsFormsApplication1\Form1.resx
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\obj\
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\
     文件         868  2019-10-21 17:15  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        8230  2019-10-21 17:15  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2019-10-21 16:58  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2019-10-21 16:58  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2019-10-21 16:58  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2019-10-21 17:17  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\TempPE\
     文件       13312  2019-10-21 17:08  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\TempPE\Web References.localhost.Reference.cs.dll
     文件        1563  2019-10-21 17:16  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt
     文件        1012  2019-10-21 17:13  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache
     文件        2702  2019-10-21 16:59  webservice文件上传下载\demo\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csprojResolveAssemblyReference.cache
............此处省略74个文件信息

评论

共有 条评论