DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2007
    Posts
    16

    How to close/delete a file

    Hi there,

    I've created a filw which my system uses to e-mail to users of my system. Below is the code i use to create the file:
    Code:
    string strVCard = vcg.Generate();
            FileInfo fi = new FileInfo("" + firstn + "" + lastn + "" + ".vcf");
            StreamWriter sw = fi.CreateText();
            sw.Write(strVCard);
            sw.Flush();
            sw.Close();
    This is fine but i wish to close the file and delete it after i have e-mailed it. However it won't let me do either as it is being used by another program which is Visual Studio itself. I have tried sw.Dispose() and then fi.Delete() but i was again told that the file was being used by another program.

    How do i firstly close it and then delete the file?

    Thanks,

    Adrian.

  2. #2
    Join Date
    Jul 2004
    Posts
    364

    Smile Deleting a File

    Try this:

    File.Delete(path)

    Hope this helps. It worked for me.

    jb

Similar Threads

  1. Problem compiling a C++ file in Linux
    By kepler in forum C++
    Replies: 3
    Last Post: 08-26-2007, 12:11 AM
  2. Database not properly created
    By Arjuna in forum Database
    Replies: 2
    Last Post: 07-25-2007, 03:22 AM
  3. Replies: 6
    Last Post: 08-16-2006, 10:32 PM
  4. Either Overwrite or Rename file
    By Shaitan00 in forum Java
    Replies: 1
    Last Post: 04-06-2005, 06:04 AM
  5. Test a file to see if it's open
    By JohnN in forum VB Classic
    Replies: 12
    Last Post: 05-08-2001, 04:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links