Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:16:11+00:00 2026-06-12T20:16:11+00:00

cannot delete image files in folder. i know it locked and used by another

  • 0

cannot delete image files in folder. i know it locked and used by another process but i dont know which process holding it and how to unlock the image files so i can delete it. tried to guess by putting .Dispose() method in every loop ending but no luck. >_<

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

using System.Net;
using System.Drawing;
using System.IO;

using AForge.Video;
using AForge.Video.VFW; //video recording

namespace example
{
    public partial class LiveRecording2 : System.Web.UI.Page
    {
        AVIWriter writer = new AVIWriter("MSVC");

        protected void Page_Load(object sender, EventArgs e)
        {

        }

         private void Get1Image()
        {
             for (int i = 0; i < 11; i++)
             {
                string ImagePath = Server.MapPath("~\\Videos\\liveRecording2\\") + string.Format("{0}", i + 1) + ".jpg";
                string ip = "http://example.ip.com:portNo/jpeg.cgi";
                string sourceURL = ip;
                WebRequest req = (WebRequest)WebRequest.Create(sourceURL);
                req.Credentials = new NetworkCredential("userName", "password");
                WebResponse resp = req.GetResponse();
                Stream stream = resp.GetResponseStream();
                Bitmap bmp = (Bitmap)Bitmap.FromStream(stream);
                bmp.Save(ImagePath);
            }
        }

        private void doRecording()
        {
            string ImagePath = Server.MapPath("~\\Videos\\liveRecording2\\");
            string SavingPath = Server.MapPath("~\\Videos\\liveRecording2\\"); //recorded video path
            string VideoName = "ICS-" + String.Format("{0:yyyyMMdd_hhmmss}", DateTime.Now) + ".avi";
            writer.Open(SavingPath + VideoName, 640, 480); //create an AVI file and open it for images adding

            // create frame image
            Bitmap image = new Bitmap(320, 240);
            //var cubit = new AForge.Imaging.Filters.ResizeBilinear(320, 240);
            string[] files = Directory.GetFiles(ImagePath);
            writer.FrameRate = 25;
            int index = 0;
            int failed = 0;
            foreach (var item in files)
            {
                index++;
                try
                {
                    image = Image.FromFile(item) as Bitmap;
                    //image = cubit.Apply(image);

                    for (int i = 0; i < 5; i++)
                    {
                        writer.AddFrame(image);
                    }
                }
                catch
                {
                    failed++;
                }
                //this.Text = index + " of " + files.Length + ". Failed: " + failed;
             }
            writer.Close();
            writer.Dispose();
            this.Label1.Text = "status: Video was successfully created";
            this.Label2.Text = "Video Path: ~/Videos/liveRecording2/" + VideoName;
            DeleteImage();
        }

       protected void Button1_Click(object sender, EventArgs e)
        {
            Get1Image();
            doRecording();
        }

        public void DeleteImage()
        {
            DirectoryInfo di = new DirectoryInfo(Server.MapPath("~\\Videos\\liveRecording2\\"));
            FileInfo[] files = di.GetFiles("*.jpg");
                             //.Where(p => p.Extension == ".jpg").ToArray();
            foreach (FileInfo file in files)
            {
                file.Delete(); // **error here**
            }

            this.Label3.Text = "Image deleted";
        }
    }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:16:12+00:00Added an answer on June 12, 2026 at 8:16 pm

    Your problem is probably here:

    image = Image.FromFile(item) as Bitmap;
    

    Try wrapping that bit of code in a using:

    using(image = Image.FromFile(item) as Bitmap)
    {
       //  rest here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that you cannot delete a cookie set by another server in javascript.
i know how to delete records for jqgrid, but i realise i cannot select
I cannot delete folder created by php mkdir for I in `echo $*` do
In my application users cannot truly delete records. Rather, the record's Deleted field gets
I cannot for the life of me find where to set the delete rules
For an iPhone Firemonkey application I am storing files (images) in the 'tmp' folder
I went behind VS2010's back and deleted some images from an image folder that's
am trying to allow a user to delete a certain image with is in
Possible Duplicate: C# 4.0 unlock image after creating BitmapImage I have this code to
I have the following code which takes an improperly saved Image from the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.