I am developing a application which requires to delete a file no matter it is being used by other process
Consider the following snippet of code.
using System;
using System.IO;
namespace DotNet_Concepts.File_Operation
{
class Deleting_File_Which_Is_In_Use
{
static void Main(string[] args)
{
StreamReader lclFileStream = null;
string lclFileName=string.Empty;
try
{
lclFileName=@"E:\Visual Studio 2008 Projects\DotNet Concepts\DotNet Concepts\Local Files\Garbage.txt";
if (File.Exists(lclFileName))
{
lclFileStream = new StreamReader(lclFileName);
if (lclFileStream != null)
{
//Doing some operation
}
//Deleting the file before closing the stream
File.Delete(lclFileName);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.StackTrace);
}
Console.ReadLine();
}
}
}
I am deleting the file which is used by the same process. Is it possible to delete the file
Thanks, Amit Shah