TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jeffrey van Dijk
NA
18
5.3k
FTP get xml file and convert to XmlDocument
Feb 21 2017 10:29 AM
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 :)
Reply
Answers (
3
)
single column divided in two column in crystal report
Exe file not running in a scheduler