Store Image to XML:
Byte [] filebytearray = new byte [filelength];// Temporarily store byte Arrays for image files
Stream streamobject = lofile. postedfile. inputstream;// Create a data stream object
// Read image file data. filebytearray is the data storage body, 0 is the Data Pointer position, and filelne is the data length.
Streamobject. Read (filebytearray, 0, filelength );
String filename = server. mappath (". \ writexml. xml"); // the file to be opened
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load (filename );
Xmlnode root = xmldoc. selectsinglenode ("dbimage"); // search for <dbguest>
Xmlnodelist xnl = xmldoc. selectsinglenode ("dbimage"). childnodes;
Int nindex = xnl. count;
// Add the following Node
Xmlelement xe1 = xmldoc. createelement ("image"); // create a <user> node
Xmlelement xesub1 = xmldoc. createelement ("imageid ");
Xesub1.innertext = nindex. tostring (); // set the text node
Xe1.appendchild (xesub1); // Add it to the <user> node
Xmlelement xesub2 = xmldoc. createelement ("imagecontenttype ");
Xesub2.innertext = lofile. postedfile. contenttype;
Xe1.appendchild (xesub2 );
Xmlelement xesub3 = xmldoc. createelement ("imagesize ");
Xesub3.innertext = filelength. tostring ();
Xe1.appendchild (xesub3 );
Xmlelement xesub4 = xmldoc. createelement ("imagedescription ");
Xesub4.innertext = tbdescription. text;
Xe1.appendchild (xesub4 );
Xmlelement xesub5 = xmldoc. createelement ("imagedata ");
Xesub5.innertext = convert. tobase64string (filebytearray );
Xe1.appendchild (xesub5 );
Root. appendchild (xe1); // Add it to the <dbguest> node.
Xmldoc. Save (filename );
Show image:
int imgid = convert. toint32 (request. querystring ["ID"]); // ID is the image id
// create a database link
string filename = server. mappath (". \ writexml. XML "); // file to be opened
xmldocument xmldoc = new xmldocument ();
xmldoc. load (filename);
xmlnodelist node = xmldoc. selectsinglenode ("// image [imageid = '" + imgid. tostring () + "']"). childnodes;
If (node! = NULL)
{< br> string strtype = node. item (1 ). innertext;
string strdata = node. item (4 ). innertext;
int nsize = int. parse (node. item (2 ). innertext);
response. contenttype = strtype; // set the output file type
// binary number of output image files
response. outputstream. write (convert. frombase64string (strdata), 0, nsize);
response. end ();
// you can save it as an image
// filestream FS = new filestream (@ "C: \ AA. BMP ", filemode. openorcreate, fileaccess. write);
// FS. write (convert. frombase64string (strdata), 0, nsize);
// FS. close ();
}