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
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Upload and Split XML Files in C#
Pintoo Yadav
Dec 16
2014
Code
3
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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