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

  • Home
  • SEARCH
  • 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 9131005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:04:09+00:00 2026-06-17T08:04:09+00:00

I am uploading a image for a user & saving it on a specified

  • 0

I am uploading a image for a user & saving it on a specified location. The code is working fine in normal scenario i.e. user selects a image & save it, it works.

Challenge occurs when user selects a image( probably wrong image due to mistake) & don’t save it, but again selects a new image & then saves it.
This scenario gives me the error :

“The process cannot access the file because it is being used by another process.”

When I try to delete image from the location at the time of error, file can’t be deleted with message:

“The action can’t be completed because the file is open in IIS Worker Process
Close the file and try again.”

Code is like this:

            try
            {
                if (!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);

                msf = new MemoryStream();
                bytes=FileUpload1.FileBytes;
                msf.Write(bytes, 0, bytes.Length);

                using (FileStream stream = new FileStream(folder + "/" + filename, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    //converting any graphic file type to jpeg format
                    Image img = Image.FromStream(msf);
                    img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

                    msf.WriteTo(stream);
                    IsuploadSuccess = true;
                    img.Dispose();
                }
            }
            catch
            {
                IsuploadSuccess = false;
            }
            finally
            {
                if (msf != null)
                {
                    msf.Close();
                    msf.Dispose();
                }
            }

I have tried adding “FileAccess.ReadWrite” & “FileShare.ReadWrite” in file stream, but doesn’t work either with all options in File stream.

Please help…

  • 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-17T08:04:10+00:00Added an answer on June 17, 2026 at 8:04 am

    Instead of getting solution of problem, I finally change approach to get rid to source of challenge. I change file name with UserID (unique) appended with CurrentDateTime converted to string & store it to temp folder until user save the change. This forms a different file each time for the challenge scenario. After save each file in temp folder created by the user (preceded by unique userid) is deleted & last changes are saved to respective directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am uploading image to server using base64 its working fine if image is
Trying to add carrier wave based image uploading to my user model. This works
My user is uploading an image of any size XX x YY. I want
I am uploading image using filedrop.js. Code in application.js file looks like this:- $(.droparea).each(function(event){
I have an Image uploading application running on carrierwave which restrict user from uploading
How can I check the size of an image a user is uploading? Client
My app is a simple uploader built for uploading image to web services. User
I have a scenario where a user uploads an image file. I strip the
I am uploading a user image in mvc2 web application. User can upload an
I'm implementing a user-based image uploading tool for my website. The system should allow

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.