• 大小: 466KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C#
  • 标签: 传输图片  

资源简介

上传图片和下载图片,使用的时候先要在你要上传的服务端用IIS发布webservice接口

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;

namespace WebApplication1
{
    /// 
    /// WebService 的摘要说明
    /// 

    [WebService(Namespace = “http://tempuri.org/“)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    // [System.Web.script.Services.scriptService]
    public class WebService : System.Web.Services.WebService
    {

        /// 
        /// 上传图片
        /// 

        /// 
        /// 
        /// 
        [WebMethod]
        public bool images(byte[] centen string pathandna string fileName)
        {
            //得到图片名称进行截取,判断是否为空
            int index = fileName.LastIndexOf(“.“);
            if (index == 0)
            {
                return false;
            }
            else
            {
                string extenden = string.Empty;
                if (index + 1 == fileName.Length)
                {
                    return false;
                }
                else
                {
                    //得到后缀名进行判断
                    extenden = fileName.Substring(index + 1);
                    if (extenden == “jpg“ || extenden == “png“ || extenden == “gif“)
                    {
                        try
                        {
                            //判断是否有该文件,没有则创建
                            if (Directory.Exists(@pathandna))
                            {
                                Directory.CreateDirectory(@pathandna);
                            }
                            //创建新建文件夹并把图片存放进去
                            File.WriteAllBytes(pathandna + @“\“ + fileName centen);
                            return true;
                        }
                        catch (Exception ex)
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return false;
        }


        /// 
        /// 下载图片
        /// 

        /// 
        /// 
        [WebMethod]
        public byte[] getImages(string imFileName)
        {
            //得到判断是否有想要看的图片地址有没有
            if (string.IsNullOrEmpty(imFileName))
            {
                throw new ArrayTypeMismatchException(“不能为空“);
            }
            else
            {
                return getbingImages(imFileName);
            }
        }

        public byte[] getbingImages(string ImFileName)
        {
            //新建一个images 而二进制数组
            byte[] images;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-11-09 09:12  Winfrom_webservice\
     目录           0  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\
     目录           0  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\
     目录           0  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Properties\
     文件        1350  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Properties\AssemblyInfo.cs
     目录           0  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Properties\PublishProfiles\
     文件         656  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Properties\PublishProfiles\WEBIMAGES.pubxml
     文件         946  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Properties\PublishProfiles\WEBIMAGES.pubxml.user
     文件        1245  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Web.Debug.config
     文件        1306  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Web.Release.config
     文件         356  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\Web.config
     文件        5105  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\WebApplication1.csproj
     文件        1201  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\WebApplication1.csproj.user
     文件         103  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\WebService.asmx
     文件        4528  2016-11-10 09:42  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\WebService.asmx.cs
     目录           0  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\bin\
     文件        6144  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\bin\WebApplication1.dll
     文件       13824  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\bin\WebApplication1.pdb
     目录           0  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\
     目录           0  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\
     文件        8234  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2016-11-10 09:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\TempPE\
     文件           0  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2016-11-09 14:08  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     文件         561  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\WebApplication1.csproj.FileListAbsolute.txt
     文件        3318  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\WebApplication1.csprojResolveAssemblyReference.cache
     文件        6144  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\WebApplication1.dll
     文件       13824  2016-11-09 16:58  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Debug\WebApplication1.pdb
     目录           0  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Release\
     文件        8236  2016-11-09 14:54  Winfrom_webservice\WindowsFormsApplication1\WebApplication1\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache
............此处省略82个文件信息

评论

共有 条评论

相关资源