Ließt eine Binärdatei (.doc, .pdf, .bmp) ein und speichert den Inhalt base64 codiert in einer XML Datei ab.
/// <summary>
/// Write a binary File (e.g. .doc, .pdf, .bmp) into a XML File
/// </summary>
/// <param name="pathBinary"></param>
/// <param name="pathXML"></param>
private void BinaryToXML(string pathBinary, string pathXML)
{
FileInfo fileInfo = new FileInfo(pathBinary);
FileStream fileStream = new FileStream(pathBinary, FileMode.Open);
BinaryReader binaryReader = new BinaryReader(fileStream);
byte[] data = binaryReader.ReadBytes((int)fileInfo.Length);
XmlWriter xmlWriter = XmlWriter.Create(pathXML);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("BinaryFile");
xmlWriter.WriteBase64(data, 0, data.Length);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
}
Kommentare zum Snippet