System.Net.WebClient.DownloadFile(Uri address, String fileName)

namespace:System.Net

参数:

address:The URI from which to download data.
fileName:The name of the local file that is to receive the data.

eg:

 /// <summary>
/// 保存文件到本地
/// </summary>
/// <param name="filePath">uri</param>
/// <param name="folderPath">localDir</param>
/// <param name="localFilePath">folderPath+fileName</param>
public void SaveDownFile(string filePath, string folderPath, string localFilePath)
{
try
{
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
WebClient DownFile = new WebClient();
DownFile.DownloadFile(filePath, localFilePath);
logger.WriteSystemLog(LogLevel.Const, "successfully saveDownFile:" + localFilePath);
}
catch (Exception ex)
{
logger.WriteExceptionLog(ex, " saveDownFile Exception: httpUrl=" + filePath);
}
}
 public static long userId = ;
public static string userCode;
public static string token;
public static string clientIP;
// 单点登录
protected void sso()
{
clientIP = GetClientIP();// local IP
userId = GetUserId();
userCode = GetUserCode();
token = sendMessage(userId, userCode, clientIP);// 发送验证消息 if (!string.IsNullOrEmpty(token))
{
delayTime();
simLogin(token);
}
} // 登录
private void simLogin(string token)
{
var url = string.Format("http://192.168.12.250:8900/Login?userId={0}&clientIP={1}&token={2}", userCode, clientIP, token);
WebClient wc = new WebClient();
byte[] ret = wc.DownloadData(url);
} private void delayTime(double secend)
{
DateTime tempTime = DateTime.Now;
while (tempTime.AddSeconds(secend).CompareTo(DateTime.Now) > )
System.Windows.Forms.Application.DoEvents();
}

C#WebClient常见用法的更多相关文章

  1. Linux中find常见用法

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  2. php中的curl使用入门教程和常见用法实例

    摘要: [目录] php中的curl使用入门教程和常见用法实例 一.curl的优势 二.curl的简单使用步骤 三.错误处理 四.获取curl请求的具体信息 五.使用curl发送post请求 六.文件 ...

  3. Guava中Predicate的常见用法

    Guava中Predicate的常见用法 1.  Predicate基本用法 guava提供了许多利用Functions和Predicates来操作Collections的工具,一般在 Iterabl ...

  4. find常见用法

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  5. iOS 开发多线程篇—GCD的常见用法

    iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...

  6. iOS开发多线程篇—GCD的常见用法

    iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...

  7. [转]EasyUI——常见用法总结

    原文链接: EasyUI——常见用法总结 1. 使用 data-options 来初始化属性. data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我 ...

  8. NSString常见用法总结

    //====================NSStirng 的常见用法==================== -(void)testString { //创建格式化字符串:占位符(由一个%加一个字 ...

  9. [转]Linux中find常见用法示例

    Linux中find常见用法示例[转]·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \;find命令的参 ...

随机推荐

  1. UltraEdit 所有快捷键 说明

    快捷键              命令                      说明                              -------------------+------- ...

  2. win10 64bits信捷触摸屏download usb口驱动程序的安装

    [问题描述] win10 64bits,信捷触摸屏开发软件,下载的时候需要安装驱动程序. 用的以前的win7 64bits的驱动程序,直接双击安装,显示无法操作注册表,需要管理员模式. 使用管理员权限 ...

  3. windows多线程相关

    1.多线程同步的方法 a)entercirticalsection leaveciriticalsection b)Mutex互斥对象 waitforsingleobject releasemutex ...

  4. world machine, 输出lightmap

    一,输出黑白lightmap: 二,输出彩色lightmap: 需要注意的是:当输出黑白lightmap时,输出设备要用Height Output:当输出彩色lightmap时,输出设备要用Bitma ...

  5. Docker之功能汇总

    Docker-给容器做端口映射 基本的命令是 -P(大写) :Docker 会随机映射一个 49000~49900 的端口到内部容器开放的网络端口基本的命令是 -p(小写) :Docker则可以指定要 ...

  6. yii2整理

    对于yii的研究,还没有那么深刻,之所以在这种情况下写,还是考虑到了后来入门人没有中文资料,而又无可下手的尴尬境地.希望对新手和我自己多一份帮助吧.总结几个自己的经验吧.环境的配置我就不做解释了.这个 ...

  7. c#调用C++DLL参数对应

    //c++:Byte(unsigned   char)     ----    c#:System.Byte         //c++:SHORT(short)              ----  ...

  8. 数据库&数据仓库

    数据仓库的定义: 世界公认的数据仓库概念创始人W.H.Inmon在<数据仓库>(Building the Data Warehouse)一书中对数据仓库的定义是:数据仓库就是面向主题的.集 ...

  9. HTC Vive开发笔记之UI Guideline

    本文转自HTC官方论坛,原址https://www.htcvive.com/cn/forum/chat.php?mod=viewthread&tid=1641&extra=page=1 ...

  10. c#深拷贝

    /// <summary> /// 对象拷贝 /// </summary> /// <param name="obj">被复制对象</pa ...