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>