Can you show the code that you are using currently. Are all your streams to all your files closed ?
Main Topics
Browse All Topicshi experts,
in my program I'm loading pictures from files into an array. then I'm stitching them together and saving as a single picture file. after that I need to delete the single files but thez remain locked (apparently because of loading into the array). how can I unlock those files to be able to delete them from the folder?
thanks in advance
d.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
here is a part of the code where I'm loading the images, stitching them and on the end deleting them...(or at least trying to)
DirectoryInfo fileInfo = new DirectoryInfo(Transfer_Dat
FileInfo[] bmpInfo = fileInfo.GetFiles("*.bmp")
int side = Convert.ToInt32(Math.Sqrt(
Image[] images = new Image[bmpInfo.Length];
for (int index = 0; index < bmpInfo.Length; index++)
{
images[index] = Image.FromFile(Transfer_Da
}
Image newBmp = new Bitmap(width * side, height * side);
//renderImg.renderedImageB
//renderImg.renderedImageB
for (int i = 0; i < bmpInfo.Length; i++)
{
Image destBmp = newBmp; //renderImg.renderedImageB
Image srcBmp = images[i];
int Y = (side - 1) - Convert.ToInt32(Math.Floor
int X = i - (Convert.ToInt32(Math.Floo
Graphics graphics = Graphics.FromImage(destBmp
graphics.DrawImage(srcBmp,
newBmp = destBmp;
//renderImg.renderedImageB
}
Image original = newBmp; //renderImg.renderedImageB
int resizedW = Convert.ToInt32(renderSetu
int resizedH = Convert.ToInt32(renderSetu
Image resized = new Bitmap(original, resizedW, resizedH);
//renderImg.renderedImageB
resized.Save(Transfer_Data
string[] filePaths = Directory.GetFiles(Transfe
foreach (string filePath in filePaths)
File.Delete(filePath);
Business Accounts
Answer for Membership
by: Rahu_ketu_patalPosted on 2009-07-29 at 01:34:43ID: 24968095
The Bitmap constructor that takes a file path will hold a lock on the image file that you are loading for the life of that bitmap. If you call dispose on the bitmap before disposing of the picture box you will get an exception. If you want to load an image from the filesystem without holding a lock on the file you should use the following code:
try
{
Image image = null;
using( Stream s = new FileStream( sourceImageFile, FileMode.Open ) )
{
image = Image.FromStream(s);
s.Close();
}
picturebox.Image = image;
}
catch
{
// Log the error
}
It is worth noting that this will throw an exception if the file you are trying to open is readonly. To avoid this you should use the FileStream overload which takes a file access mode and set it to FileAccess.Read