द्वारा किया जा रहा है मैं जो इसे अन्य प्रक्रियाएक फ़ाइल जबरदस्ती हटाया जा रहा है, भले ही यह अन्य प्रक्रिया
द्वारा किया जा रहा है निम्नलिखित स्निपेट पर विचार करें कोई बात नहीं एक फ़ाइल को नष्ट करने की आवश्यकता है एक आवेदन के विकास कर रहा हूँ।
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
{
[email protected]"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();
}
}
}
मैं उसी प्रक्रिया द्वारा उपयोग की जाने वाली फ़ाइल को हटा रहा हूं। यह संभव फ़ाइल को हटाने का है
धन्यवाद, अमित शाह
लेकिन फ़ाइल उपयोग में है। तो इसे क्यों हटाएं? –
डुप्लिकेट - http://stackoverflow.com/questions/1040/how-do-i-delete-a-file-which-is-locked-by-another-process-in-c? –
यह आपके प्रश्न से स्पष्ट नहीं है, अगर आप एक फाइल खोलना चाहते हैं जिसे आपने खोला है। यदि ऐसा है, तो एड स्वैंगरेन की सलाह का उपयोग करें। –