Skip to Content
0
Former Member
Mar 06, 2009 at 11:49 PM

How do I show a photo via an instance of a .net object in the report?

17 Views

Hi

I want to display a photo in a crystal report using Visual Studio 2008.

I'm not using a traditional database, I'm using a .net object (see below).

I'm attaching to an instance of my object via ".net objects".

I'm able to add (drag and drop) the photo field to the report. However, the "photo" never shows up when I go to view the report.

I'm able to view the "name" and "price" values of my object in the report.

I suspect I don't know what type to return in my object to get the image to show up.

I'm returning an array of bytes: public byte[] GetPhoto

Can you please point me in the right direction?

Thanks,

Brian.

public class Product

{

private string m_name;

private int m_price;

private string m_photo;

public Product(string name, int price, string photo)

{

m_name = name;

m_price = price;

m_photo = photo;

}

public string Name

{

get

{

return m_name;

}

}

public int Price

{

get

{

return m_price;

}

}

public byte[] GetPhoto

{

get

{

System.IO.FileStream fs = new System.IO.FileStream(@"C:\Users\brian\Pictures\GPS Test Photos\" + m_photo, FileMode.OpenOrCreate, FileAccess.Read);

byte[] MyData = new byte \[ fs.Length \]; //Make room

fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));

fs.Close();

return MyData;

}

}

}

public class Merchant

{

private List<Product> m_products;

public Merchant()

{

m_products = new List<Product>();

m_products.Add(new Product("Pen", 25, "R0010107.JPG"));

m_products.Add(new Product("Pencil", 30, "R0010108.JPG"));

m_products.Add(new Product("Notebook", 15, "R0010109.JPG"));

}

public List<Product> GetProducts()

{

return m_products;

}

}

Edited by: nezaz2000 on Mar 7, 2009 12:52 AM