Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 24, 2012 07:12 AM by Allen Li - MSFT
Member
181 Points
251 Posts
May 22, 2012 08:55 PM|LINK
Hi friends,
I have a .DAT fiel with data in it in the following format
<Msg time='2010-11-19T17:55:22' type='INFO1' code='111' target='Server' thread='9852'>Customer is regular Type </Msg>
I want to split those as
MsgTime ,type,code,target,serverthread,Desc fields in order to make an insert to database to corresponding fields...How can I Achieve it....
Thank you
Participant
1144 Points
239 Posts
May 22, 2012 09:22 PM|LINK
Akpaga,
If the .DAT file have only valid XML content (as it seems on the case you presented), you may iterate through each data entry in the way listed on the following KB entry:
http://support.microsoft.com/kb/307548
Hope it works for you.
Star
10411 Points
1196 Posts
May 24, 2012 07:12 AM|LINK
Hi, you can split the file with codes manually, for example:
using (StreamReader sr = new StreamReader(Server.MapPath("~/test.dat"))) { String line; while ((line = sr.ReadLine()) != null) { string substr = line.Substring(line.IndexOf("'")+1); string MsgTime = substr.Substring(0,substr.IndexOf("'")); Response.Write(MsgTime + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string type = substr.Substring(0, substr.IndexOf("'")); Response.Write(type + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string code = substr.Substring(0, substr.IndexOf("'")); Response.Write(code + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string target = substr.Substring(0, substr.IndexOf("'")); Response.Write(target + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string thread = substr.Substring(0, substr.IndexOf("'")); Response.Write(thread + "<br />"); substr = substr.Substring(substr.IndexOf(">") + 1); string Desc = substr.Substring(0, substr.IndexOf("<")); Response.Write(Desc + "<br />"); } }
akpaga22
Member
181 Points
251 Posts
How to read a .DAT file and parse it
May 22, 2012 08:55 PM|LINK
Hi friends,
I have a .DAT fiel with data in it in the following format
<Msg time='2010-11-19T17:55:22' type='INFO1' code='111' target='Server' thread='9852'>Customer is regular Type </Msg>
I want to split those as
MsgTime ,type,code,target,serverthread,Desc fields in order to make an insert to database to corresponding fields...How can I Achieve it....
Thank you
OnoSendai
Participant
1144 Points
239 Posts
Re: How to read a .DAT file and parse it
May 22, 2012 09:22 PM|LINK
Akpaga,
If the .DAT file have only valid XML content (as it seems on the case you presented), you may iterate through each data entry in the way listed on the following KB entry:
http://support.microsoft.com/kb/307548
Hope it works for you.
Allen Li - M...
Star
10411 Points
1196 Posts
Re: How to read a .DAT file and parse it
May 24, 2012 07:12 AM|LINK
Hi, you can split the file with codes manually, for example:
using (StreamReader sr = new StreamReader(Server.MapPath("~/test.dat"))) { String line; while ((line = sr.ReadLine()) != null) { string substr = line.Substring(line.IndexOf("'")+1); string MsgTime = substr.Substring(0,substr.IndexOf("'")); Response.Write(MsgTime + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string type = substr.Substring(0, substr.IndexOf("'")); Response.Write(type + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string code = substr.Substring(0, substr.IndexOf("'")); Response.Write(code + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string target = substr.Substring(0, substr.IndexOf("'")); Response.Write(target + "<br />"); substr = substr.Substring(substr.IndexOf("'") + 1); substr = substr.Substring(substr.IndexOf("'") + 1); string thread = substr.Substring(0, substr.IndexOf("'")); Response.Write(thread + "<br />"); substr = substr.Substring(substr.IndexOf(">") + 1); string Desc = substr.Substring(0, substr.IndexOf("<")); Response.Write(Desc + "<br />"); } }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework