webclient上传文件和附加信息
来源:互联网 发布:淘宝上架宝贝时间限制 编辑:程序博客网 时间:2024/05/17 06:59
使用WebClient上传,通常用的方法很简单,使用_WebClient.UploadFile(ServerUrl, "post", FilePath)即可,最近做一个项目,上传的文件每次保存的路径不一致,所以就需要上传文件的同时,上传一些附加信息进行判断进而决定保存的位置。
上传页面upload.aspx:
protected void Page_Load(object sender, EventArgs e)
...{
try
...{
string FilePath = @"1.log";
WebClient _WebClient = new WebClient();
NameValueCollection nvcObj = new NameValueCollection();
//附加信息
nvcObj .Add("MyKey", "1");
//将附加信息添加至webclient对象
_WebClient.QueryString = nvcObj ;
_WebClient.UploadFile("http://.../DownloadFile.aspx", "post", FilePath);
}
catch (WebException _WebException)
...{
Response.Write(_WebException.Message.ToString());
Response.Write(_WebException.StackTrace );
}
}
protected void Page_Load(object sender, EventArgs e)
...{
try
...{
string FilePath = @"1.log";
WebClient _WebClient = new WebClient();
NameValueCollection nvcObj = new NameValueCollection();
//附加信息
nvcObj .Add("MyKey", "1");
//将附加信息添加至webclient对象
_WebClient.QueryString = nvcObj ;
_WebClient.UploadFile("http://.../DownloadFile.aspx", "post", FilePath);
}
catch (WebException _WebException)
...{
Response.Write(_WebException.Message.ToString());
Response.Write(_WebException.StackTrace );
}
}
下载页面DownloadFile.aspx
protected void Page_Load(object sender, EventArgs e)
{
{
string result = Request.QueryString["MyKey"].ToString();
foreach (string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
{
HttpPostedFile file = Request.Files[f];
if(result =="1")
{
file.SaveAs("D://uploadfile1//" + file.FileName);
file.SaveAs("D://uploadfile1//" + file.FileName);
}
else
{
file.SaveAs("D://uploadfile2//" + file.FileName);
}
}
}
}
}
- webclient上传文件和附加信息
- webclient上传文件
- 利用WebClient上传文件
- C#WebClient上传文件
- 使用WebClient或HttpWebRequest模拟上传文件和数据
- 使用WebClient或HttpWebRequest模拟上传文件和数据
- 使用WebClient或HttpWebRequest模拟上传文件和数据
- 使用WebClient或HttpWebRequest模拟上传文件和数据
- 使用WebClient实现文件上传
- 使用WebClient类上传文件
- C# Webclient 文件远程上传
- WebClient上传文件到ashx
- 使用WebClient上传文件时的错误问题解决和上传例子
- asp.net 如何用webclient上传文件
- .Net WebClient 上传文件错误集锦
- 关于webClient 上传文件的总结
- .Net WebClient 上传文件错误集锦
- c# WebClient上传文件到远程服务器
- linux 字符驱动模板
- 一个水晶报表绑定DataSet的实例
- 无情六月+迷途羔羊
- asp.net的页面生存周期
- 窘迫的生活
- webclient上传文件和附加信息
- win2003+iis6+php+gd2+mysql安装配置:图解
- FrameCountry数据访问层架构帮助说明
- FrameCountry数据访问层架构配置文件说明
- 博鸽V1.5发布了~~
- javascript多图片各种渐变循环
- FrameCountry数据访问层架构日志信息
- 路灯&雪
- 反射