0

Is there any library in the .NET Framework which allows us to create, delete & wipe out disk partition programmatically in .NET? (I am using VB.NET)

At the moment the option I'm using is going through dos command 'diskpart', which I feel is not efficient in coding point of view.

Dennis
  • 3,528
  • 4
  • 28
  • 40
  • 1
    Check here http://stackoverflow.com/questions/1232398/how-to-programically-format-sd-card-on-fat16-on-windows-net and here http://stackoverflow.com/questions/8063538/format-a-drive-from-c-sharp – Tobiasz Jul 01 '13 at 08:53

1 Answers1

2

Try this...

Imports System.Text

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Try
        Dim partitionLetter As String = "Q"
        Dim sb As StringBuilder = New StringBuilder()
        sb.AppendLine("SELECT DISK=0") 'Select the first disk drive
        sb.AppendLine("CREATE PARTITION PRIMARY") 'create new partition
        sb.AppendLine("ASSIGN LETTER=" + partitionLetter) 'assign letter
        sb.AppendLine("FORMAT FS=FAT32 LABEL=""FD"" QUICK") 'format new partition
        sb.AppendLine("EXIT")
        System.IO.File.WriteAllText("c:\part.scr", sb.ToString()) 'create diskpart script
        Process.Start("diskpart.exe", "/s c:\part.scr") 'run the script
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub

End Class
AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
Sankar
  • 6,908
  • 2
  • 30
  • 53