Share via


Extract iso file programatically using c# code

Question

Monday, January 12, 2015 7:38 AM

Hi all,

I have a requirement where I have to create a web application using asp.net C#. And this web application should have the feature to extract the .iso file.How can I do this using c# code ?

Could you please help me with this.

Thanks for help in advance.

All replies (6)

Monday, January 12, 2015 8:09 AM âś…Answered

After searching for a while on the net I found the following code snippet working for me. Thanks to StackOverflow link

http://stackoverflow.com/questions/10579964/extract-iso-with-winrar-automatically-with-c-sharp-or-batch

string Desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Process.Start("Winrar.exe", string.Format("x {0} {1}",
   Desktop + "\\test.rar",
   Desktop + "\\SomeFolder"));

We can change .rar extension to .iso extension to extract the .iso file.


Monday, January 12, 2015 8:12 AM

Hi,

this thread might help you.

http://stackoverflow.com/questions/10579964/extract-iso-with-winrar-automatically-with-c-sharp-or-batch


Friday, April 3, 2015 11:10 AM | 1 vote

Hi NathCorp,

you can use .NET DiscUtils library :

using DiscUtils;
using DiscUtils.Iso9660;

void ExtractISO(string ISOName, string ExtractionPath)
{
    using (FileStream ISOStream = File.Open(ISOName, FileMode.Open))
    {
        CDReader Reader = new CDReader(ISOStream, true, true);
        ExtractDirectory(Reader.Root, ExtractionPath + Path.GetFileNameWithoutExtension(ISOName) + "\\", "");
        Reader.Dispose();
    }
}
void ExtractDirectory(DiscDirectoryInfo Dinfo, string RootPath, string PathinISO)
{
    if (!string.IsNullOrWhiteSpace(PathinISO))
    {
        PathinISO += "\\" + Dinfo.Name;
    }
    RootPath += "\\" + Dinfo.Name;
    AppendDirectory(RootPath);
    foreach (DiscDirectoryInfo dinfo in Dinfo.GetDirectories())
    {
        ExtractDirectory(dinfo, RootPath, PathinISO);
    }
    foreach (DiscFileInfo finfo in Dinfo.GetFiles())
    {
            using (Stream FileStr = finfo.OpenRead())
            {
                using (FileStream Fs = File.Create(RootPath + "\\" + finfo.Name)) // Here you can Set the BufferSize Also e.g. File.Create(RootPath + "\\" + finfo.Name, 4 * 1024)
                {
                    FileStr.CopyTo(Fs, 4 * 1024); // Buffer Size is 4 * 1024 but you can modify it in your code as per your need
                }
            }
    }
}
static void AppendDirectory(string path)
{
    try
    {
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
    }
    catch (DirectoryNotFoundException Ex)
    {
        AppendDirectory(Path.GetDirectoryName(path));
    }
    catch (PathTooLongException Exx)
    {
        AppendDirectory(Path.GetDirectoryName(path));
    }
}

Mark as answer or vote as helpful if you find it useful | Ammar Zaied [MCP]


Wednesday, June 10, 2015 2:06 AM

Hello,

Thank you, I am using your code. I would like to mention only one thing.

The line inside method EsxtractISO, 

 ExtractDirectory(Reader.Root, ExtractionPath + Path.GetFileNameWithoutExtension(ISOName) + "\", "");

Should be:

  ExtractDirectory(Reader.Root, ExtractionPath + "\" + Path.GetFileNameWithoutExtension(filename) + "\", "");

Thank you

Bill


Tuesday, January 5, 2016 12:40 PM

Hi!

My problem Link Project


Tuesday, January 5, 2016 2:43 PM

Just to add to this thread, there's a Powershell command for that:

Mount-DiskImage

David

David http://blogs.msdn.com/b/dbrowne/