write to temp file & delete it

Posted on 2005-05-02
Last Modified: 2010-05-18

I'm trying to write some text to a file:

StreamWriter sw = new StreamWriter(filePath, false))

then later i need to delete the file:

// get rid of the file

but i get an exception when i try to delete:

The process can not access the file 'C:\Documents and Settings\TREVORXPS\ASPNET\LOCALS~1\Temp\tmpA3.tmp' because it is being used by another process.

how do i solve this?

thanks - Trevor
Question by:trevorhartman
    LVL 33

    Accepted Solution

    Trevor, it looks like you are doing everything correct.  As you probably know, you get errors like this when you don't close open streams to the file.  No other code touches that file before the deletion?  If you can't determine the source, head over here, and get this utility.  You can use it to see which process has the file open (likely aspnet_wp.exe)
    LVL 15

    Assisted Solution

    i had the same problem once..and restarting it fixed it..
    LVL 8

    Author Comment

    hmm, works now, thanks :)

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now