webservice下载文件
WebService项目中的Web.config配置代码 ??? <appSettings> WebService项目中的ImageService.asmx代码 Winform项目中的窗体下载按钮代码 Winform项目中的窗体下载按钮调用函数 ??????? /// <summary> ??????? /// 通过WebService下载文件 ??????? /// </summary> ??????? /// <param name="ServiceFilePath">服务器图片路径</param> ??????? /// <param name="DownloadFolderPath">本地图片路径</param> ??????? private string DownloadImage(string ServiceFilePath,string DownloadFolderPath) ??????? { ??????????? try ??????????? { ??????????????? string DownloadFileName=""; ??????????????? if (ServiceFilePath.Contains("/")) ??????????????? { ??????????????????? DownloadFileName=ServiceFilePath.Substring(ServiceFilePath.LastIndexOf("/")); ??????????????? } ??????????????? else ??????????????? { ??????????????????? DownloadFileName = ServiceFilePath; ??????????????? } ??????????????? string DownloadFilePath = DownloadFolderPath +""+ DownloadFileName; ??????????????? localhost.ImageService myImageService=new localhost.ImageService(); ??????????????? byte[] bytes = myImageService.DownloadFile(ServiceFilePath); ??????????????? if (bytes != null) ??????????????? { ??????????????????? if (!Directory.Exists(DownloadFolderPath)) {? ??????????????????????? Directory.CreateDirectory(DownloadFolderPath); ??????????????????? } ??????????????????? if (!File.Exists(DownloadFilePath)) ??????????????????? { ??????????????????????? File.Create(DownloadFilePath).Dispose(); ??????????????????? } ??????????????????? //如果不存在完整的上传路径就创建 ??????????????????? FileInfo downloadInfo = new FileInfo(DownloadFilePath); ??????????????????? if (downloadInfo.IsReadOnly) { downloadInfo.IsReadOnly = false; } ??????????????????? //定义并实例化一个内存流,以存放提交上来的字节数组。 ??????????????????? MemoryStream ms = new MemoryStream(bytes); ??????????????????? //定义实际文件对象,保存上载的文件。 ??????????????????? FileStream fs = new FileStream(DownloadFilePath,FileMode.Create); ??????????????????? ///把内内存里的数据写入物理文件 ??????????????????? ms.WriteTo(fs); ??????????????????? fs.Flush(); ??????????????????? ms.Flush(); ??????????????????? ms.Close(); ??????????????????? fs.Close(); ??????????????????? fs = null; ??????????????????? ms = null; ??????????????? } ??????????????? return "下载成功"; ??????????? } ??????????? catch(Exception ex) ??????????? { ??????????????? return "下载失败"+ex.Message; ??????????? } ??????? } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- umount不掉挂载点时的处理方法
- scala – Spark SQL:来自csv的自动模式
- angularjs – Angular中select和ng-repeat的问题
- 根据wsdl生成一个webservice 的.cs文件
- Gvim:Ubuntu字母间距(Consolas字体)
- bash – 如何将stdin从shell脚本重定向到shell脚本中的命令
- jax-ws webservice部署到tomcat 遇到的问题
- AngularJS – 如何对所有jsons请求进行deflate和编码/解码到
- 如何在Unix中使用mput将多个文件夹FTP到另一台服务器?
- angularjs – 在Angular伪指令模板中有条件地添加数据属性