WebClient DownloadData-System.ArgumentException:路径不是合法形式

时间:2018-06-29 16:04:08

标签: c# path directory webclient webclient-download

我在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

谁能告诉我为什么我的URI错误?还是我格式化不正确?我已经尝试了几种不同版本的URI,但是它们都引发了异常。我试图摆脱http://,我试图摆脱www,但这似乎并不能解决我的问题。

0 个答案:

没有答案
相关问题