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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:11:03+00:00 2026-06-10T09:11:03+00:00

I have written a web app that has to save a few files. I

  • 0

I have written a web app that has to save a few files. I have developed this app in C# using Visual Web Developer 2010 Express. The program executes flawlessly in VWD but when I deploy it to the server it runs into problems. One problem in particular is that the files being saved are held onto by some process and I can’t access them or delete them when I need to. I believe I am properly closing the file streams. Here is an example of one such save:

string[] lines = MessagesTextbox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
string messagesFileLocation = currDir + "\\" + reportDir + "\\" + messagesFile;
FileStream fs2 = File.Open(messagesFileLocation, FileMode.Create, FileAccess.Write);
using (StreamWriter sw = new StreamWriter(fs2))
{
    sw.WriteLine("<Messages>");
    foreach (string message in lines)
    {
        if (!message.Equals(""))
        {
            sw.WriteLine("\t<message>" + message + "</message>");
        }
    }
    sw.WriteLine("</Messages>");
}
fs2.Close();

The problem is also occurring when I use HtmlAgilityPack to save the rendered HTML to a file.

The only difference between my development environment and the server is that on the server my app runs under IIS. Can anyone think of a reason why this problem might occur using IIS when it doesn’t occur ever in my development environment? The person who administers the server thinks it has to be my code but, like I said, it has been running for several weeks on my own machine without any of these problems.

Any suggestions are appreciated.

Regards.

  • 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-10T09:11:05+00:00Added an answer on June 10, 2026 at 9:11 am

    Your FileStream fs2 will not be closed if an Exception is thrown. You must close it in a finally block, which you get for free if you wrap it in its own using.

    Everything that implements IDisposable should be wrapped in a using block (or otherwise disposed for some advanced cases) as a matter of good coding practice. There are edge cases to be sure where that does not matter, but it is a solid habit to always ensure that IDisposable.Dispose() is called as soon as an object that implements the interface is no longer required.

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

Sidebar

Related Questions

Say I have a mobile web app written using JQuery Mobile, this app retrieves
I have a web app that has been written with the assumption that autocommit
I have a legacy intranet web app that was written for IE7 and contains
I have web application written in java using Eclipse. It has just one servlet
I have a very large problem. I've written a large app using Flex3/Tomcat/BlazeDS/Spring that
I have an app written in PHP, MySQL, etc. The app has a few
I've written a web application using Catalyst that has a lot of forms and
I have written a basic Windows Form app in C# that has an embedded
I have a web app that has to do something every, let's say first
I have a web application written in Django that has one specific page I'd

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.