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. Spring 学习历程(二)

    JUnit测试 maven导入包 <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> &l ...

  2. 如何生成指定架构的Linux内核默认配置文件

    答: make ARCH=<cpu architecture> defconfig 举例如下: make ARCH=arm64 defconfig (编译系统将会去目录arch/arm64 ...

  3. hihoCoder week17 最近公共祖先·三 lca st表

    记录dfs序列,dfn[tot] 记录第tot次访问的节点 然后查两点在dfs序中出现的第一次 id[u] id[v] 然后  找 dep[k] = min( dep[i] ) {i 属于 [id[u ...

  4. Css下拉菜单设置

    <style type="text/css"> *{margin:0px;padding:0px;}设置所有标签属性<初始化页面属性> #nav{backg ...

  5. 论文笔记:Semantic Segmentation using Adversarial Networks

    Semantic Segmentation using Adversarial Networks 2018-04-27 09:36:48 Abstract: 对于产生式图像建模来说,对抗训练已经取得了 ...

  6. 论文笔记之:Deep Attributes Driven Multi-Camera Person Re-identification

    Deep Attributes Driven Multi-Camera Person Re-identification 2017-06-28  21:38:55    [Motivation] 本文 ...

  7. Arch 安装后,一些基本设置(1)

    1.安装成功后新建普通用户不能使用useradd进行一步添加,应该下载adduser交互式添加新用户,否则用户无法登陆. 2.安装openkeeper之前需要安装ppp和net-tools (需要里面 ...

  8. windows特殊文件或文件夹

    考了很多文章,搜集了很多资料整理而成.好的用途可以用来隐藏个人资料,防止误删,病毒免疫等等.至于坏的方面,当然也可用来隐藏木马等等,就看你怎么用了.还有一个没有搞明白,资料上也没找到,请知道的指点一下 ...

  9. BZOJ 2648 SJY摆棋子(KD Tree)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2648 题意: 思路: KDtree模板题. 参考自http://www.cnblogs.com/ra ...

  10. video组件的使用

    <video width="100%" height="100%" :src="downloadUrl" controls=" ...