XML : How do I load image to DataGridView from XML file if it contains other data?

Currently I'm using next code. But it returns a byte string to the DataGridView.

  public static DataView LoadToDataview()              {                  using (XmlReader xmlFile = XmlReader.Create(pathToXml, new XmlReaderSettings()))                  {                      DataSet ds = new DataSet();                      DataView dv;                      ds.ReadXml(xmlFile);                        dv = new DataView(ds.Tables[1]);                      return dv;                  }              }    

This string I recieve from property and write it to xml.

  public Bitmap Image      {          get { return image; }          set { image = value; }      }        [XmlAttribute("Image")]      public byte[] PictureByteArray      {          get          {              TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));              return (byte[])converter.ConvertTo(image, typeof(byte[]));          }          set          {              image = new Bitmap(new MemoryStream(value));          }      }    

My xml, besides images, contains other data types.

  <Products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <Products_>      <MedicineProduct        Product_Name="Some Name"        Price="0"        Quntity="0"        Expiration_Date=""        Storage_Conditions=""        Image="/9j/4AAQSkZJRgABAQEAYABgAAD - // - // bla bla bla"      </MedicineProduct>    </Products_>  </Products>    

How can I return an image from XML file? I need to convert all my data to byte array when writing to xml?

No comments:

Post a Comment