Summary (4) - Save Image to XML file

xiaoxiao2021-03-17  197

Summary (4) - Save Image to XML file

Squire: Terrylee

One. Save pictures to XML files

1

/ ** /

///

2 /// Save pictures to XML file 3 ///

4

Private

Void

UploadImageToxml ()

5

{6 / ** //// give users to upload file 7 string strFilePathName = loFile.PostedFile.FileName; 8 string strFileName = Path.GetFileName (strFilePathName); 9 int FileLength = loFile.PostedFile.ContentLength; 10 if ( FileLength <= 0) 11 return; 12 try13 {14 / ** //// Image file temporary storage Byte array 15 byte [] filebyteaRray = new byte [fileLength]; 1617 / ** //// Establish data stream pair Like 18 Stream StreamObject = Lofile.postedFile.InputStream; 1920 / ** //// Read Image File Data, FileByteArray is a data storage body, 0 is a data pointer location, fileELnegth is the data length 21 streamObject.read (FilebyTearray, 0 , FileLength; 2223 / ** ///////> Document 24 string filename = server.mappath (".// Writexml.xml"); 25 26 xmlDocument xmldoc = new xmldocument (); 27 xmldoc.load (filename ); 2829 / ** /// / Find 30 xmlnode root = xmldoc.selectsinglenode ("dbimage"); 31 xmlnodelist XNL = XmLDoc.selectsinglenode ("dbimage). ChildNodes; 32 int NINDEX = xnl.count; 3334 / ** //// The following add new node 35 xmlelement XE1 = XMLDoc.createele Ment ("image"); // Create a node 3637 xmlelement Xesub1 = xmldoc.createElement ("ImageID"); 38 39 / ** //// Settings text Node 40 XESUB1.INNERTEXT = NINDEX.TOSTRING () 4142 / ** //// Add to Node 43 XE1.Appendchild (Xesub1); 44 xmlelement Xesub2 = XmLDoc.createElement ("ImageContentType"); 45 xesub2.innertext = Lofile.postedFile.conteType; 46 XE1 .Appendchild (Xesub2); 47 xmlelement Xesub3 = xmldoc.createElement ("ImageSize"); 48 xesub3.innertext = filelength.tostring (); 49 XE1.Appendchild (Xesub3); 50 xmlelement XESUB4 =

xmlDoc.CreateElement ( "ImageDescription"); 51 xesub4.InnerText = tbDescription.Text; 52 xe1.AppendChild (xesub4); 53 XmlElement xesub5 = xmlDoc.CreateElement ( "ImageData"); 54 xesub5.InnerText = Convert.ToBase64String (FileByteArray) 55 XE1.Appendchild (Xesub5); 56 57 / ** /// Add to Node 58 root.appendchild (Xe1); 59 xmldoc.save (filename); 60 61 Response.Redirect ("ShowallImg. ASPX "); 62} 63 Catch (Exception EX) 64 {65 Throw EX; 66} 67} II. Read image data from XML

1

/ ** /

///

2 /// Read images from XML 3 /// 4 /// 转载请注明原文地址:https://www.9cbs.com/read-129654.html

New Post(0)