Asp.net XML import database (3)

Source: Internet
Author: User

Protected void btnsumit_click (Object sender, eventargs E)
{
System. Drawing. Image IMG;
Conn. open ();
Using (sqlcommand cmd = new sqlcommand ())
{
Cmd. Connection = conn;
Cmd. commandtype = commandtype. text;

String Path = server. mappath ("XML. xml ");
Xmldocument xml = new xmldocument ();
XML. Load (PATH );
Xmlnodelist node = xml. getelementsbytagname ("resault ");
Foreach (xmlelement N in node)
{
String strdata = n. childnodes [1]. innertext;
Int nsize = n. childnodes [1]. innertext. length;
// Response. outputstream. Write (convert. frombase64string (strdata), 0, nsize );

 

memorystream MS = new memorystream (convert. frombase64string (strdata);
IMG = system. Drawing. image. fromstream (MS);

string url = server. mappath ("img/");
directoryinfo dir = new directoryinfo (URL);
fileinfo [] filecount = dir. getfiles ();
int I = filecount. length;
string imgname = URL + (I + 1) + ". jpg ");
IMG. save (imgname);

Cmd. commandtext = string. format ("insert into img2 (title, IMG) values ('" + N. childnodes [0]. innertext + "','" + imgname + "')");
Cmd. executenonquery ();
Clientscript. registerstartupscript (this. GetType (), "", "<SCRIPT> alert ('imported successfully') </SCRIPT> ");


}
}
Conn. Close ();
}

XML structure:
<? XML version = "1.0" standalone = "yes"?>
<Documentelement>
<Resault>
<ID> 179 </ID>
"image stream" </img>
</Resault>
<Resault>
<ID> 180 </ID>
"image stream" </img>
</Resault>

<Documentelement>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.