- FtpWebRequest fwr = (FtpWebRequest)WebRequest.Create("ftp://**********/httpdocs/App/" + MainWindow.admRelatie + "/" + filename);
- fwr.Credentials = new NetworkCredential(Username, Password);
- fwr.UseBinary = true;
- fwr.Method = WebRequestMethods.Ftp.DownloadFile;
- FtpWebResponse response = (FtpWebResponse)fwr.GetResponse();
- Stream s = response.GetResponseStream();
-
- StreamReader reader = new StreamReader(s);
-
- string x = reader.ReadToEnd();
-
- MessageBox.Show(x);
-
- XmlDocument xml = new XmlDocument();
-
- xml.Load(s);
That is the code I am currently using to get the file from the FTP but I am always getting an error saying illegal characters, if I then debug the xml string, I see there is still \n\r and a lot of spaces everywhere in the XML. I at first thought it was the encoding but even if I explicitly say its UTF-8 it still doesn't work, if I then do use the reader.Readline(); instead of read to end and just store every line in a List then it gets rid of the '\n\r' but it still has a lot of empty spaces in the xml which causes the illegal character problem.
Then ofcourse I could get rid of the empty spaces by doing str.Replace(" ", ""); but then the problem is that some of values inside the xml also have spaces I do not want to get rid of.
I woud love some help :)