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格式 "

解决方案 »

  1.   

    url= http:\\192.168.0.126\C:\temp.xls 
    那里错了啊?
    关键
      

  2.   

    http:\\192.168.0.126\C:\temp.xls 
    你在192.168.0.126中有C:这个虚拟目录?
      

  3.   

    是不是正确的url,很简单,你先在ie地址栏里输一下,看是不是出现下载对话框就知道了
      

  4.   

    http:\\192.168.0.126\C:\temp.xls 
    这种中间加个C:的,,,不知道可不可以,你是要下C盘下的吧,要下载也要是发布了的,放到一个虚拟目录下,如建个虚拟目录,指向文件temp.xls,假设虚拟目录名为tthttp:\\192.168.0.126\C:\temp.xls  中的\\应该换成//吧,?
      

  5.   

    先在iis里建个虚拟目录,指向c盘,虚拟目录名为test
    生成的url就是http://192.168.0.126/test/temp.xls
      

  6.   

    ?请问下你的问题解决了没  我的现在是上传报这个错  请帮个忙看一下  谢谢/// <summary>
            /// 上传文件
            /// </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("请选择要上传的文件!");
                }
            }