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 6157059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:43:13+00:00 2026-05-23T20:43:13+00:00

I have a little app that is supposed to read through an XML document

  • 0

I have a little app that is supposed to read through an XML document that the user uploads. If the file doesn’t have the proper nodes, the file is deleted and the user is notified.

However, the file is always locked when I try to delete it, both in code and through windows explorer. It stays locked until I refresh the page in IE.

myDoc.Load(FileUpload2.FileContent);
string XMLpath = Server.MapPath(ConfigurationSettings.AppSettings["PDFLocation"]) + FileUpload2.FileName;
myDoc.Save(XMLpath);
file = new FileInfo(XMLpath);

//here I check if the file is valid. If not, delete

file.Delete(); //This is where it throws the "cannot access the file" error

the full text of the error:

The process cannot access the file 'C:\project\files\file.xml' because it is being used by another process. 

I tried putting in FileUpload2.FileContent.Dispose(); and FileUpload2.Dispose(); before the delete statement, but no luck.

How do I release the file for deletion?

  • 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-05-23T20:43:13+00:00Added an answer on May 23, 2026 at 8:43 pm

    You shouldn’t save the XML file to disk at all until you know it’s valid.

    To answer your question, you left an open FileStream somewhere in the elided code.
    You need to Dispose() it, preferably by using a using statement.

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

Sidebar

Related Questions

I have an app that I've written in C#/WinForms ( my little app ).
I have a little one-liner in my Rails app that returns a range of
I have a little logging app (written in wxPython) that receives data from a
I am learning flex and have written a little app with a TextArea that
I have an app that I'm writing a little wizard for. It automated a
I have made a little app for signing up for an event. User input
I have an app that is a little bit slow. I thoutght it could
I have a nice little app on the app store that does pretty well
I have little Silverlight app that needs to make queries to server, is it
I have a little app that downloads stock prices and was working perfectly (for

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.