码迷,mamicode.com
首页 > 其他好文 > 详细

c# 单个文件上传至服务器

时间:2014-07-10 09:59:22      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   文件   os   

#region 单个文件上传至服务器
/// <summary>
/// 单个文件上传至服务器
/// </summary>
/// <param name="uriAddress">接收文件资源的URI, 例如: http://xxxx/Upload.aspx?UID=11111</param>
/// <param name="filePath">要发送的资源文件, 例如: @"D:\workspace\WebService 相关.doc</param>
/// <returns>返回文件保存的相对路径, 例如: "upload/xxxxx.jpg" 或者出错返回 ""</returns>
public static string UploadFile(string uriAddress, string filePath)
{
//利用 WebClient
System.Net.WebClient webClient = new System.Net.WebClient();
webClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
byte[] responseArray = webClient.UploadFile(uriAddress, "POST", filePath);
string savePath = System.Text.Encoding.ASCII.GetString(responseArray);
return savePath;
}
catch (Exception)
{
return "";
}
}
#endregion

 

c# 单个文件上传至服务器,布布扣,bubuko.com

c# 单个文件上传至服务器

标签:style   blog   http   color   文件   os   

原文地址:http://www.cnblogs.com/lxctboy/p/3812490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!