Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[C#] Mono - How do I delete resource file(s)

How to delete resource from name?

Code
public static void RemoveResource(AssemblyDefinition asmDefinition)
{
  foreach (var v in asmDefinition.MainModule.Resources.OfType<EmbeddedResource>()) // result: Mono.Cecil.EmbeddedResource
  {
    Console.WriteLine(v);

    int index = asmDefinition.MainModule.Resources.IndexOf(v); // result: 0 1
    Console.WriteLine(index);
    asmDefinition.MainModule.Resources.RemoveAt(index); // Delete
  }
}

1 - Doesn't delete all resources by index.
2 - How to delete resource files by resource file name?

The resources contain files:

FileText.txt, MusicList.wav

I need to delete resources by name namely: FileText and MusicList
Well i didnt understand your couples of first lines but what you want to do is using txt file and wav file and then delete them after?

its sample but tricky:
be sure to dispose correctly these resources:
you can use IDisposable interface and implementing a Dispose function or in the case of files you can use them inside a using block
Code
using(StreamReader sr = new StreamReader(path/to/your/txtfile.txt)
{
var x = sr.ReadToEnd();
}
i prefer using a using block because once code jump out of the using the resource is automatically disposed
or
Code
StreamReader sr = new StreamReader(path/to/your/txtfile.txt)
var x = sr.ReadToEnd();
sr.Close();
there is alot of way to dispose

then
Code
if(File.Exist(path/to/your/file)
{
File.Delete(path/to/your/file);
}


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Help] by john ronaldsadAug 18, 2024 05:58 PM 1 142 Aug 18, 2024 05:58 PM
Last Post: Lookdadon
[.NET] by Wumbology ExpertOct 24, 2020 06:21 AM 11 2,580 Oct 24, 2020 06:21 AM
Last Post: sh@rp
[.NET] by mutchimAug 6, 2019 12:34 AM 3 287 Aug 6, 2019 12:34 AM
Last Post: mutchim