private bool DownLoad(string url, string savePath)
{
string fileName; //被下载的文件名
if (url.IndexOf("\\") > -1)
{
fileName = url.Substring(url.LastIndexOf("\\") + 1);
}
else
{
fileName = url.Substring(url.LastIndexOf("/") + 1);
}
if (!savePath.EndsWith("/") && !savePath.EndsWith("\\"))
{
savePath = savePath + "/";
} savePath += fileName; //另存为的绝对路径+文件名 WebClient client = new WebClient();
try
{
client.DownloadFile(url, savePath);
}
catch(Exception exd)
{
MessageBox.Show(exd.Message);
return false; } return true;
}
url: http:\\192.168.0.126\C:\temp.xls
本机IP:192.168.0.136
服务器:192.168.0.126
从服务器下载文件
运行时出现"不支持URI格式 "
{
string fileName; //被下载的文件名
if (url.IndexOf("\\") > -1)
{
fileName = url.Substring(url.LastIndexOf("\\") + 1);
}
else
{
fileName = url.Substring(url.LastIndexOf("/") + 1);
}
if (!savePath.EndsWith("/") && !savePath.EndsWith("\\"))
{
savePath = savePath + "/";
} savePath += fileName; //另存为的绝对路径+文件名 WebClient client = new WebClient();
try
{
client.DownloadFile(url, savePath);
}
catch(Exception exd)
{
MessageBox.Show(exd.Message);
return false; } return true;
}
url: http:\\192.168.0.126\C:\temp.xls
本机IP:192.168.0.136
服务器:192.168.0.126
从服务器下载文件
运行时出现"不支持URI格式 "
解决方案 »
- 【求助】怎么判断某个For循环执行成功,成功则Messagebox提示成功?
- 如何实现文件压缩
- 结构体
- vs2010工具箱里的控件没了,要怎么办啊?
- 帮帮我吧,都快哭了!!数据库查询!50分送!!!!
- Treeview 拖动时候的节点显示问题,在以前的问题中搜不到
- 怎么把2个DataTable里的数据合并到一个DataTable里,请高手们指导一下
- 未处理的“System.ArgumentException”类型的异常.大家帮帮忙!
- 在DataGrid中,如何删除一行?
- 我使用如下的代码为什么不能正确获取Image的Region?
- (急!在线等)如何根据Code39字体生成条码并打印的问题
- 有没有winform下的html富文本编辑器?
那里错了啊?
关键
你在192.168.0.126中有C:这个虚拟目录?
这种中间加个C:的,,,不知道可不可以,你是要下C盘下的吧,要下载也要是发布了的,放到一个虚拟目录下,如建个虚拟目录,指向文件temp.xls,假设虚拟目录名为tthttp:\\192.168.0.126\C:\temp.xls 中的\\应该换成//吧,?
生成的url就是http://192.168.0.126/test/temp.xls
/// 上传文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void btnUpload_Click(object sender, EventArgs e)
{
TreeNodeCollection tnNodeColl = trvFile.Nodes; int nodeCount = tnNodeColl.Count; int successCount = 0; if (nodeCount > 0)
{
string loadPath = //"http://222.92.198.67/MobileService/update";// Application.StartupPath+"/images"; 错误就是这
string nodeText = string.Empty;
string nodeTipText = string.Empty; foreach (TreeNode node in tnNodeColl)
{
if (node.Checked)
{
nodeText = node.Text.ToString();
nodeTipText = node.ToolTipText; //这可以控件上传文件类型 string loadFile = loadPath + "\\"+nodeTipText;
bool isExists = JudgeFileExists(loadFile, nodeTipText);
if (isExists) {
byte[] btFile = FileToBinary(nodeText);
if (BinaryToFile(loadFile, btFile))
{
node.Checked = false;
successCount++;
continue;
}
else
{
break;
}
}
else
{
continue;
}
}
else
{
continue;
}
}
string strCue = "成功上传" + successCount.ToString() + "个文件。\n";
int failCount = nodeCount - successCount;
strCue += "上传失败" + failCount.ToString() + "个文件。\n";
this.label1.Text = strCue; //上传后的提示显示
}
else
{
MessageBox.Show("请选择要上传的文件!");
}
}