代码之家  ›  专栏  ›  技术社区  ›  Baddack

WebClient下载数据-系统参数异常:路径不是合法形式

  •  0
  • Baddack  · 技术社区  · 8 年前

    我在Winforms中使用以下代码从ftp站点下载一个txt文件。代码可以工作,因为我可以下载文件,但是我遇到了一个异常。我的调试器正在向 DownloadData 功能。

    string versionInfoPathFTP = @"http://www.metoneftp.com/software/BCLoadCorr/version.txt";
    
    private void check_FTP()
    {
        string currentVersion;          //this programs version
        string latestVersion;           //newest version read from server
    
        WebClient wc = new WebClient();
        currentVersion = Application.ProductVersion.Replace(".*", "");
    
        try
        {
            byte[] newFileData = wc.DownloadData(versionInfoPathFTP);
            string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
            latestVersion = fileString;
    
            var latest = new Version(latestVersion);
            var current = new Version(currentVersion);
    
            var result = current.CompareTo(latest);
    
            if (result < 0)         //new version available
            {
                do_update_FTP(latestVersion);
            }
            else if (result == 0)   //at current latest version
            {
                labelInfo.Text = "Program is up to date! (" + latestVersion.ToString() + ")";
            }
            else                   //future version?
            {
                labelInfo.Text = "Current version is the latest!";
            }
    
            wc.Dispose();
        }
        catch (Exception ex)
        {
            labelInfo.Text = "No internet connection available!";
            Console.WriteLine(ex.ToString());
        }
    }
    

    下面是引发的异常:

    A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
    System.ArgumentException: The path is not of a legal form.
       at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
       at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
       at System.IO.Path.GetFullPathInternal(String path)
       at System.Net.WebClient.GetUri(String path)
       at System.Net.WebClient.DownloadData(String address)
       at MetOneUpdater.UpdateControl.check_FTP() in J:\Products\Software\Automatic Software Updates\MetOneUpdater\MetOneUpdater\MetOneUpdater\UpdateControl.cs:line 65
    

    http:// ,我试着摆脱 www 但它似乎不能解决我的问题。

    0 回复  |  直到 8 年前