James kumar
James kumar

Reputation: 7

Image saving and retrieving from database

I have to take an image from my system and save it in the form of bytes to a folder in the server.Than i have to give the path of the .txt file i.e the converted image file to the database by creating a table in it.Finally i want to retrieve it from the database.It should be a windows application.Is this possible?

Upvotes: 0

Views: 456

Answers (2)

Virus
Virus

Reputation: 2541

Yes it is possible...

You are just storing the path of the image file that you created. The path is just going to be a simple string.

While retrieving, you need to take the path from the database and set it as the image source path to the ImageBox in the windows application.

Example:

for selecting the image file.

string DestinationPath = "D:\\test.jpg";
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    byte[] bt = File.ReadAllBytes(ofd.FileName);
    File.WriteAllBytes(DestinationPath, bt);
}
//Store DestinationPath into the database.

for retrieving and displaying in a PictureBox

string pathFromDatabase = "D:\\test.jpg"; //Retrieve from database
pboxDisplay.Image = Image.FromFile(pathFromDatabase); //Assuming pboxDisplay as the PictureBox control 

hope it helps...

Upvotes: 2

Aravind
Aravind

Reputation: 1549

try this

from data base

byte bt =  File.ReadAllBytes("C:\\test.jpg");
File.WriteAllBytes("C:\\test1.jpg",bt)

    " bt "   you can upload this byte to Database while retrieving bytes from data base use File.WriteAllbytes ...   

Upvotes: 0

Related Questions