SoFunction
Updated on 2025-03-09

How to save the image to an XML file


/// <summary>
/// Save the picture to XML file
/// </summary>
private void UploadImageToXml()
{
///Get the file name that the user wants to upload
string strFilePathName = ;
string strFileName = (strFilePathName);
int FileLength = ;
if(FileLength<=0)
return;
try
{
/// Image file temporarily stores Byte array
Byte[] FileByteArray = new Byte[FileLength];

/// Create data flow object
Stream StreamObject = ;

///Read image file data, FileByteArray is the data storage body, 0 is the data pointer position, and FileLnegth is the data length
(FileByteArray,0,FileLength);

///The file to be opened
string fileName = (".\\");

XmlDocument xmlDoc = new XmlDocument();
(fileName);

/// Find <dbGuest>
XmlNode root=("dbImage");
XmlNodeList xnl=("dbImage").ChildNodes;
int nIndex = ;

///Add new nodes below
XmlElement xe1=("Image");//Create a <User> node
XmlElement xesub1=("ImageID");

///Set text node
=();

///Add to the <User> node
(xesub1);
XmlElement xesub2=("ImageContentType");
=;
(xesub2);
XmlElement xesub3=("ImageSize");
=();
(xesub3);
XmlElement xesub4=("ImageDescription");
=;
(xesub4);
XmlElement xesub5=("ImageData");
= Convert.ToBase64String(FileByteArray);
(xesub5);

///Add to the <dbGuest> node
(xe1);
(fileName);

("");
}
catch(Exception ex)
{
throw ex;
}
}