WPF 从服务器下载文件
1、先获取服务器下载地址,给出要下载到的目标地址
public void DownloadFileFromServer()
{
string serverFilePath = "http://192.168.1.222:9111/Doc/Test.docx";
string serverFileName = string.Empty;
int nameIndex = serverFilePath.LastIndexOf("/");
if (nameIndex > )
{
serverFileName = serverFilePath.Substring(nameIndex + );
}
string dirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test");
if (!Directory.Exists(dirPath))
{
DirectoryInfo directoryInfo = new DirectoryInfo(dirPath);
directoryInfo.Create();
}
string targetPath = Path.Combine(dirPath, serverFileName);
DownloadFile(serverFilePath, targetPath);
}
2、下载
public void DownloadFile(string serverFilePath, string targetPath)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverFilePath);
WebResponse respone = request.GetResponse();
Stream netStream = respone.GetResponseStream();
using (Stream fileStream = new FileStream(targetPath, FileMode.Create))
{
byte[] read = new byte[];
int realReadLen = netStream.Read(read, , read.Length);
while (realReadLen > )
{
fileStream.Write(read, , realReadLen);
realReadLen = netStream.Read(read, , read.Length);
}
netStream.Close();
fileStream.Close();
}
}
WPF 从服务器下载文件的更多相关文章
- 【FTP】C# System.Net.FtpClient库连接ftp服务器(下载文件)
如果自己单枪匹马写一个连接ftp服务器代码那是相当恐怖的(socket通信),有一个评价较高的dll库可以供我们使用. 那就是System.Net.FtpClient,链接地址:https://net ...
- (4)FTP服务器下载文件
上一篇中,我们提到了怎么从FTP服务器下载文件.现在来具体讲述一下. 首先是路径配置.. 所以此处我们需要一个app.config来设置路径. <?xml version="1.0&q ...
- Python 实现批量从不同的Linux服务器下载文件
基于Python实现批量从不同的Linux服务器下载文件 by:授客 QQ:1033553122 实现功能 1 测试环境 1 使用方法 1 1. 编辑配置文件conf/file_for_downl ...
- 从Linux服务器下载文件到本地命令
从Linux服务器下载文件夹到本地1.使用scp命令 scp /home/work/source.txt work@192.168.0.10:/home/work/ #把本地的source.txt文件 ...
- 从Linux服务器下载文件夹到本地
从Linux服务器下载文件夹到本地 1.使用scp命令 scp /home/work/source.txt work@192.168.0.10:/home/work/ #把本地的source.txt文 ...
- Java Web实现使用浏览器从服务器下载文件(后台)
Java Web实现 使用浏览器从服务器下载文件. 下面实现两种情况的下载,需求如下: 需求(一):1.用户在页面填写表单. 2.填写完成后,选择下载,将表单内容发往后台. 3.后台根据内容生产一个文 ...
- js从服务器下载文件
通常,将文件绝对路径url作为超链接<a>的链接地址href的值,点击<a>后,浏览器将会尝试请求文件资源,如果浏览器能够辨认文件类型,则将会以预设的打开方式直接打开下载的文件 ...
- C#从服务器下载文件到客户端源码
1.在window窗体加个button控件,双击进去
- C# 从服务器下载文件代码的几种方法
一.//TransmitFile实现下载 protected void Button1_Click(object sender, EventArgs e) { /* 微软为Response对象提供了一 ...
随机推荐
- 简单递归____Fibonacci数列
#include <stdio.h> int fun(int x) { ||x==) ; else return fun(x-1)+fun(x-2); } int main() { int ...
- 六、SpringBoot配置@ConfigurationProperties与@Value区别
1.@Value的使用 三种用法 // ${key} 从环境变量.配置文件中取值 @Value("${person.last-name}") private String last ...
- CSS 3D 的魅力
作者 | 子慕大诗人 来源 | www.cnblogs.com/1wen/p/9064011.html 前言: 最近玩了玩用css来构建3D效果,写了几个demo,所以博客总结一下. 在阅读 ...
- HTML+CSS+JS是什么
html:整合网页结构和内容显示的一种语言 css:是一种用来表现HTML或XML等文件样式的计算机语言 js:增加表现力的脚本 做网页前台设计的标准套装,html是一些网页控件,css是美化这些控件 ...
- POJ1149PIGS
传送门 貌似是最大流建图优化入门题(可惜我还是不会) 最暴力的建图当然是源点连每个猪圈然后猪圈需要拆成n个点分给每个人这个必定是跑不过的 所以我们可以进行优化 很明显没有被动过的猪圈一直是不变的可以不 ...
- Jquery中的offset()和position()深入剖析(元素定位)
先看看这两个方法的定义. offset(): 获取匹配元素在当前视口的相对偏移. 返回的对象包含两个整形属性:top 和 left.此方法只对可见元素有效. position(): 获取匹配元素相对父 ...
- 【leetcode】993. Cousins in Binary Tree
题目如下: In a binary tree, the root node is at depth 0, and children of each depth k node are at depth ...
- spring MVC 返回值信息和ResponseBody的响应json数据
spring mvc的界面返回: 如果我们定义的返回类型是String 那么我们返回的时候直接写入 我们的界面的名字就可以了 springmvc会自动去找到我们的界面,如果是void类型的返回那么 ...
- 【单例模式】懒汉式的线程安全问题 volatile的作用
原文链接:https://blog.csdn.net/Activity_Time/article/details/96496579 ****** 1. 懒汉式的Java实现 public class ...
- Python Numpy 矩阵级基本操作(1)
NumPy的操作介绍 import numpy as np #导入numpy包,简写为np print "Generate 1*10 matrix" a=np.arange(1,1 ...