webService 

  /// <summary>
/// 上传图片webServer 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public bool UpdateFile(byte[] content, string pathand,string filename)
{
string pathandname = pathand + filename;
int index = pathandname.LastIndexOf(".");
if (index == )
{
return false;
}
else
{
string extended = string.Empty;
if (index + == pathandname.Length)
{
return false;
}
else
{
extended = pathandname.Substring(index + );
if (extended == "jpeg" || extended == "gif" || extended == "jpg" ||
extended == "bmp" || extended == "png")
{
try
{
if (!Directory.Exists(@pathand))//若文件夹不存在则新建文件夹
{
Directory.CreateDirectory(@pathand); //新建文件夹
} //File.WriteAllBytes(Server.MapPath(pathandname), content);
File.WriteAllBytes(pathandname, content);
return true;
}
catch (Exception ex)
{
return false;
}
}
else
{
return false;
}
}
}
}
} //测试 private void btnSaveServer_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string pathand = CommonClass.Config.GetAppSettings<string>("ProductImageUrl",
@"D:\FSTERP\ProductImage\");
string imagename = "mylove";
bool uploadResult = UploadImageWebService(fileDialog.FileName, pathand, imagename);
if (uploadResult)
MessageBox.Show("上传成功!");
else
MessageBox.Show("上传失败!");
}
}
/// <summary>
/// 上传图片[通过webServer]
/// </summary>
/// <param name="filename">选择图片路径[默认选择文件包括后缀名]</param>
/// <param name="pathand">上传服务器文件夹[文件夹不存在则新建]</param>
/// <param name="imagename">上传后图片文件名[不包括后缀名]</param>
/// <returns>上传结果</returns>
public bool UploadImageWebService(string filename, string pathand, string imgname)
{ string extension = Path.GetExtension(filename).ToLower().Replace(".", "");
string paramSuffix = "|" + CommonClass.Config.GetAppSettings<string>("ImageFormat",
"jpg|jpge|gif|bmp|png") + "|";
int pi = paramSuffix.IndexOf("|" + extension + "|");
if (pi < )
{
MessageBox.Show("仅能上传jpg|jpge|gif|bmp|png格式的图片!");
return false;
}
else
{
FileInfo fileInfo = new FileInfo(filename);
if (fileInfo.Length > )
{
MessageBox.Show("上传的图片不能大于20K");
}
else
{
//Stream file = fileDialog.OpenFile();
FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[file.Length];
file.Read(bytes, , bytes.Length);
//实例化WebService服务。ServiceReference1是我们在添加引用时设置的命名空间
WebService.WebService1 webservice = new FSTERP.WebService.WebService1();
DateTime time = DateTime.Now;
//重命名图片的名称与路径
//string pathand = CommonClass.Config.GetAppSettings<string>("ProductImageUrl",
@"D:\FSTERP\ProductImage\");
string imagename = imgname + "." + extension;
//string pathandname = pathand + imagename;
if (webservice.UpdateFile(bytes, pathand, imagename))
{
return true;
}
else
{
return false;
}
}
}
return false;
}

测试图片

版权声明:本文为博主原创文章,未经博主允许不得转载。

webService上传图片的更多相关文章

  1. Sql server之路 (六)上传服务器图片

    原理: 上传图片的名字 插入到数据库里 上传图片的内容(二进制数据) 写到服务器指定的目录下 下次读取图片的时候 从数据库里的指定字段里读取图片文件名 从数据库的指定路径下 拼串成完成的路径 就可以下 ...

  2. webservice跨域上传图片

    1.上传文件,在一般处理程序中处理 //1.接收post过来的文件 HttpPostedFile file = context.Request.Files[]; || file.ContentLeng ...

  3. android之调用webservice 实现图片上传

    转:http://www.cnblogs.com/top5/archive/2012/02/16/2354517.html public void testUpload(){ try{ String ...

  4. WebService上传下载图片

    WebService服务端 接受要上传的图片 public string UploadImg(byte[] fileBytes, int id) { try { string filePath = M ...

  5. Android使用ksoap2调用C#中的webservice实现图像上传

    目录: 一. android使用ksoap2调用webservice 二. 异步调用 三. Android使用ksoap2调用C#中的webservice实现图像上传参考方法 四. 图像传输中Base ...

  6. iOS开发之结合asp.net webservice实现文件上传下载

    iOS开发中会经常用到文件上传下载的功能,这篇文件将介绍一下使用asp.net webservice实现文件上传下载. 首先,让我们看下文件下载. 这里我们下载cnblogs上的一个zip文件.使用N ...

  7. 博客使用BOS上传图片

    1.博客平台的选定 从大学开始做个人主页算起,最开始是使用html,CSSS写简单的页面,后面大学毕业之后接触到了WordPress,就开始用WordPress搭建网站.现在还维护着一个农村网站.ht ...

  8. nodejs利用ajax实现网页无刷新上传图片

    nodejs利用ajax实现网页无刷新上传图片 标签(空格分隔): nodejs 通常情况下上传图片是要通过提交form表单来实现的,但是这又不可避免的产生了网页转. 利用ajax技术和FormDat ...

  9. webService

    什么是webService WebService,顾名思义就是基于Web的服务.它使用Web(HTTP)方式,接收和响应外部系统的某种请求.从而实现远程调用.  1:从WebService的工作模式上 ...

随机推荐

  1. QSetting

    .初始化,判断是否存在ini文件,如果不存在则新建 void iniConfig() { QFileInfo fileInfo(".\\config.ini"); if (!fil ...

  2. 5.sql2008分组与嵌套

    1.Group by基本介绍;2.Having的使用;3.分组综合应用;4.子查询基本介绍;5.In/Exists/Any/Some/All;6.子查询综合应用; 1.Group by基本介绍:依据B ...

  3. Flash Memory 简介【转】

    本文转载自:https://linux.codingbelief.com/zh/storage/emmc/ Flash Memory 是一种非易失性的存储器.在嵌入式系统中通常用于存放系统.应用和数据 ...

  4. SpringBoot 注解调用Redis缓存

    注解代码: import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.l ...

  5. UVA 10318 Security Panel(DFS剪枝 + 状压 + 思维)题解

    题意:给一个r*c的矩阵开关(初始全打开的),每次按下一个开关都会改变3*3范围内的有*的地方的状态,问你最少几步能让开关全闭上,按升序输出按哪些按钮 思路:每个按钮至多按一下,按按钮的顺序和结果无关 ...

  6. Python SSH爆破以及Python3线程池控制线程数

    源自一个朋友的要求,他的要求是只爆破一个ip,结果出来后就停止,如果是爆破多个,完全没必要停止,等他跑完就好 #!usr/bin/env python #!coding=utf-8 __author_ ...

  7. How to Install Apache Tomcat 8.5 on CentOS 7.3

    How to Install Apache Tomcat 8.5 on CentOS 7.3 From: https://www.howtoforge.com/tutorial/how-to-inst ...

  8. 用js互相调用iframe页面内的js函数

    http://www.jb51.net/web/18555.html 1,首先获得右栏iframe对象 var frames=document.getElementById("frameid ...

  9. P3338 [ZJOI2014]力

    思路 颓柿子的题目 要求求这样的一个式子 \[ F_j=\sum_{i<j}\frac{q_iq_j}{(i-j)^2}-\sum_{i>j}\frac{q_iq_j}{(i-j)^2} ...

  10. 【ASP.NET】System.Web.Routing - RouteCollection Class

    Provides a collection of routes for ASP.NET routing. The RouteCollection class provides methods that ...