I am using Visual C#

When i open file from my database then an image is loaded in my program,and image source is given below

map.Source = new BitmapImage(new Uri(filePath)); /// filepath is address of image from datebase

and when replace it by another image. The new image is loaded in my picture box,

then map.Source = new BitmapImage(new Uri(filePath)); //filepath is address of new image from disk

and when i try to delete previous image from my database then it show a message that the previous is being used.

How can I make image source of previous image free??

I think solution Taken from here should work.

private void LoadMapImage(string filepath)
            if (!string.IsNullOrEmpty(filepath))
                FileInfo info = new FileInfo(filepath);
                if (info.Exists && info.Length > 0)
                    BitmapImage bi = new BitmapImage();
                    bi.DecodePixelWidth = (int)Map.Width;
                    bi.CacheOption = BitmapCacheOption.OnLoad;
                    bi.UriSource = new Uri(info.FullName);
                    Map.Source = bi;

use Dispose()

for example:

Bitmap bmp = new Bitmap(FileUpload1.FileContent);
This question has already been answered. Start a new discussion instead.