Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to Upload and Split XML Files in C#
WhatsApp
Pintoo Yadav
Dec 16
2014
3.2
k
0
1
if
(Page.IsValid)
{
// string fileName = fileupld.PostedFile.FileName;
bool
m_UpdateFlag;
// int m_TotRec, m_AcceptRec, m_rejRec;
m_UpdateFlag =
false
;
if
(fileupld.PostedFile.FileName ==
""
|| fileupld.PostedFile.FileName ==
null
)
{
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Information"
,
"alert('Please Select the XML file ');"
,
true
);
fileupld.Focus();
return
;
}
if
(File.Exists(Server.MapPath(
"~/source/"
) + System.IO.Path.GetFileName(fileupld.FileName)))
//if (File.Exists(Server.MapPath(ConfigurationManager.AppSettings["source"].ToString() + fileupld.PostedFile.FileName)))
{
fileupld.SaveAs(Server.MapPath(
"~/ErrorLog/"
) + System.IO.Path.GetFileName(fileupld.FileName));
// PanelError.Visible = true;
lblMsg.Text =
"This File <b>"
+ fileupld.PostedFile.FileName +
"</b> already exists on the server."
;
return
;
}
if
(File.Exists(Server.MapPath(
"~/source/"
) + System.IO.Path.GetFileName(fileupld.FileName)))
{
File.Delete(Server.MapPath(
"~/source/"
) + System.IO.Path.GetFileName(fileupld.FileName));
}
fileupld.SaveAs(Server.MapPath(
"~/source/"
) + System.IO.Path.GetFileName(fileupld.FileName));
string
FileName = fileupld.FileName.ToString();
FileName = FileName.Substring(0, 3);
// FileType
strACKFile = Path.GetFullPath(Server.MapPath(
"~/source/"
) + System.IO.Path.GetFileName(fileupld.FileName));
if
(strACKFile.Trim().Length == 0)
{
ScriptManager.RegisterStartupScript(
this
.Page,
this
.GetType(),
"Warning"
,
"alert('Please Select The XML File');"
,
true
);
fileupld.Focus();
return
;
}
string
xmlFilePath = Server.MapPath(
"~/source/"
) + System.IO.Path.GetFileName(fileupld.FileName);
string
source1 = System.IO.File.ReadAllText(xmlFilePath);
string
source = source1.Replace(
"\r\n"
,
" "
);
//string source2 = source.Replace("\"INR\"", "'INR'");
List<
string
> destList =
new
List<
string
>();
foreach
(Match match
in
Regex.Matches(source,
"<GrpHdr>(.*?)</GrpHdr>"
))
destList.Add(match.Groups[1].Value);
string
GroupHeader = destList[0];
GroupHeader = GroupHeader.Replace(
"\t"
,
""
);
GroupHeader =
"<GrpHdr>"
+ GroupHeader +
"</GrpHdr>"
;
//GroupHeader
List<
string
> AmtList =
new
List<
string
>();
string
amt = GroupHeader.Replace(
'"'
,
' '
);
foreach
(Match match
in
Regex.Matches(amt,
"<TtlIntrBkSttlmAmt Ccy= INR >(.*?)</TtlIntrBkSttlmAmt>"
))
AmtList.Add(match.Groups[1].Value);
string
amtResult = AmtList[0];
//Amount
List<
string
> NoOfTxsList =
new
List<
string
>();
string
TxsCount = GroupHeader.Replace(
'"'
,
' '
);
foreach
(Match match
in
Regex.Matches(amt,
"<NbOfTxs>(.*?)</NbOfTxs>"
))
NoOfTxsList.Add(match.Groups[1].Value);
string
TxsCountResult = NoOfTxsList[0];
//txnNo
// string grph = GroupHeader.Replace("'INR'", "INR");
String strQ =
"insert into EBT_master(TYPE,GroupOFHeader,Amount,TXN_NO)values('"
+ FileName +
"','"
+ GroupHeader +
"','"
+ amtResult +
"','"
+ TxsCountResult +
"')"
;
DbObj.gl_ExeNonQuery(strQ);
C#
XML
Up Next
How to Upload and Split XML Files in C#