Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have saved some images in ms access database and i want to retrieve those images in Image field in front end. I have saved images in "OLE Object" format. Whenever i"m trying to retrieve those images it gives me an error "The file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\130064593738380337' already exists.". Please solve my problem. Thanks....

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        cn.Open();
        OleDbCommand cm = new OleDbCommand("select * from ImageCollection where img_id='"+DropDownList1.SelectedItem.ToString()+"'",cn);
        OleDbDataAdapter da = new OleDbDataAdapter(cm);
        OleDbDataReader dr = cm.ExecuteReader();
        try
        {
            if (dr.Read())
            {

                string image1 = Convert.ToString(DateTime.Now.ToFileTime());
                string image2 = Convert.ToString(DateTime.Now.ToFileTime());
                FileStream fs1 = new FileStream(image1, FileMode.CreateNew, FileAccess.Write);
                FileStream fs2 = new FileStream(image2, FileMode.CreateNew, FileAccess.Write);
                byte[] bimage1 = (byte[])dr["passport_photo"];
                byte[] bimage2 = (byte[])dr["sign_photo"];
                fs1.Write(bimage1, 0, bimage1.Length - 1);
                fs2.Write(bimage2, 0, bimage2.Length - 1);
                fs1.Flush();
                fs2.Flush();
                Image1.ImageUrl = Convert.ToString(fs1);
                Image2.ImageUrl = Convert.ToString(fs2);
            }
            dr.Close();
            cn.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
Posted
Comments
Richard C Bishop 27-Feb-13 12:31pm    
You are trying to write a file that already exists. Delete the existing files and then run it again. If it works this time then you will know that you have to change how you are writing the file. Maybe you could change the FileMode.CreateNew to FileMode.Append or .Open so that it just writes over or adds to the file that is already there.
Chiklu.Soumya 27-Feb-13 13:08pm    
It shows error when i wrote FileMode.Open.The error is "Could not find file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\130064619000881758'."
When I wrote FileMode.Append it shows error "The process cannot access the file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\130064617880809532' because it is being used by another process.
"
Richard C Bishop 27-Feb-13 13:43pm    
Ok, how about adding an incrementer to the file path arguement of the filestream so that each time it creates one it has a slightly different file name? Let me ask you this, where is the "image1" and "image2" variables values coming from?
Chiklu.Soumya 27-Feb-13 13:46pm    
values of image1 and image2 comes from ImageCollection table.
Richard C Bishop 27-Feb-13 13:57pm    
Ok, well I am not real sure what to do now. Hopefully someone will come along and give you a better suggestion. Sorry I could not help you.

1 solution

Retrieve ms access data with the aid of recovery for access download

Post [spam link removed] contains of many helpful solutions for restoring ms access databases
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900