Click here to Skip to main content
15,879,080 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
i want to create a virtual hard drive using visual studio , and i think DiscUtils is the easiest way to do it , so..if someone can tell me how to use it ?
Posted
Comments
keyur chauhan 1-Sep-14 2:31am    
ok..i have googled it and added the reference in my application , now i just need a code to create a VHD

1 solution

found the solution , did'nt know it was way to easy to create a vhd using DiscUtils ,
the code somehow looks like this

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiscUtils;
using DiscUtils.Fat;
using DiscUtils.Vhd;
using DiscUtils.Partitions;
using System.IO;


namespace VirtualDrive
{
    class Program
    {
        static void Main(string[] args)
        {
            long diskSize = 100 * 1024 * 1024; //100MB
            using (Stream vhdStream = File.Create(@"D:\mydisk.vhd"))
            {
                Disk disk = Disk.InitializeDynamic(vhdStream,Ownership.None,diskSize);
                BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat);
                using (FatFileSystem fs = FatFileSystem.FormatPartition(disk, 0, null))
                {
                    fs.CreateDirectory(@"TestDir\CHILD");
                    // do other things with the file system...
                }
            }
        }
    }
}
 
Share this answer
 
v2
Comments
Member 12337429 19-Feb-16 4:02am    
how can i use this code to create vhd but with windowsforms?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900