tags:

views:

25

answers:

1

I'm trying to get an .xml file that's somewhere on a server loaded into a streamerader to stream it to XML and process it. This is what i get:

EndOfStream = 'reader.EndOfStream' threw an exception of type 'System.ObjectDisposedException'

I do see that im logged in on the server etc: StatusDescription = "226 Transfer complete.\r\n"

It looks to me like the data gets closed so that i can't read out the data to my xml. What can i do to solve this?

            // Get the object used to communicate with the server.
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://194.109.xxx.xxx/alldata.xml");
            request.Credentials = new NetworkCredential("xxx", "xxx");
            request.UseBinary = true;
            request.Method = WebRequestMethods.Ftp.DownloadFile;

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            string xml = reader.ReadToEnd();
            XmlDocument thisXmlDoc = new XmlDocument();
            thisXmlDoc.LoadXml(xml);

            XPathNavigator thisNavigator = thisXmlDoc.CreateNavigator();
            XPathNodeIterator dossierNodes = thisNavigator.Select("/Dossiers/");
A: 

Stupid I didn't see that request has a propperty KeepAlive........

request.KeepAlive = true;

This made sure i could still read it after opening the doc.

Younes