Question image file locked????

caixadelixo

New member
Joined
Aug 21, 2013
Messages
1
Programming Experience
Beginner
Hi!!! Somebody knows whats the problem????
If i remove OpenFileDialog and pass the string direct pathDiskCover = @"C:\Documents and Settings\Administrator\My Documents\someImage.jpg"; it works fine.
C#:
private void toolStripButton2_Click(object sender, EventArgs e)
    {
    OpenFileDialog dlg = new OpenFileDialog();
    dlg.FileName = String.Empty;
    dlg.Title = "Open Images";
    dlg.Filter = "Image Files(*.png; *.jpg; *.bmp)|*.png; *.jpg; *.bmp";
    DialogResult dr = dlg.ShowDialog();
    if (dr == DialogResult.OK)
    {
    pathDiskCover = System.IO.Path.GetFullPath(dlg.FileName) ;
    MemoryStream ms = new MemoryStream(System.IO.File.ReadAllBytes(pathDiskCover));
    Image img = Image.FromStream(ms);
    img.Save(@"C:\output.png", ImageFormat.Png);
    img.Dispose();
    }
    dlg.Dispose();
    updateCover();
    }
    private void updateCover()
    {
    //pb_CoverMD.Image = new Bitmap(pathDiskCover);// this works
    byte[] MyData = null;
    FileStream fs = new FileStream(pathDiskCover, FileMode.OpenOrCreate, FileAccess.Read);
    MyData = new byte[fs.Length];
    fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
    fs.Close();
    if (idRecord > 0)
    {
    SQLiteConnection conn = new SQLiteConnection(conecxao);
    if (conn.State == ConnectionState.Closed) { conn.Open(); }
    SQLiteCommand cmd = new SQLiteCommand("UPDATE FilmsDB SET picCoverDB=@picCoverDB WHERE idFilm=@idFilm ", conn);
    cmd.Parameters.AddWithValue("idFilm", idRecord);
    cmd.Parameters.AddWithValue("picCoverDB", MyData);
    try
    {
    cmd.ExecuteNonQuery();
    loadDatabase();
    MessageBox.Show("Cover successfully updated.");
    }
    catch (Exception ex)
    {
    MessageBox.Show("Error updating cover." + ex.Message);
    }
    }
    }
thank you for any replay...
 
Top Bottom