简体   繁体   中英

Webclient causing an invalid operation exception

I'm trying to download a simple xml file and save it to the users local profile. When trying to download (i don't think this has anything to do with the saving location but i'm not 100% sure) i get the following exception on the webclient.

System.InvalidOperationException

My code is as follows;

public void downloadProxy()  {
            string url = Properties.Settings.Default.url;
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "/netsettings/proxies.xml");

        try
        {               
            WebClient GrabFile = new WebClient(); 
            GrabFile.DownloadFile(url, path);   
        }
        catch (WebException webEx)
        {
            if (webEx.Status == WebExceptionStatus.ConnectFailure)
            {
                Console.WriteLine("Are you behind a firewall?  If so, go through the proxy server.");
            }
        }

    }

如果您使用的是Windows操作系统,请使用反斜杠(而不是斜杠)作为文件夹分隔符:

\netsettings\proxies.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM