views:

117

answers:

3

Hey,

I'm trying to write a program that opens a folder from the CD disk when a button is clicked. The program will be run from a CD, and aims to open a certain folder. However, I can't use "shell "explorer...."" because the drive letter will change between different computers. Is there a way to open the folder straight from the CD in VB.NET

A: 
  • Find all the drive letters on the system.
  • For each drive
    • if the specific folder exists open it.
  • Loop
john
Right, thanks for that, but can you provide the specific syntax for this. Thanks :)
shmuxel
A: 

This link contains some basic stuff. It should get you pointed in the right direction. Also, take keywords from the code sample and search MSDN. MSN has lots of documentation and samples that may get you to the next step.

http://articles.techrepublic.com.com/5100-10878_11-6081470.html#

edit - try this...

Imports System.IO

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each D As DriveInfo In DriveInfo.GetDrives
            If D.DriveType = DriveType.CDRom Then
                Debug.WriteLine(D.Name)
            End If

        Next
    End Sub
End Class
Scott
+1  A: 

It is easy if you know that your program was started from the CD. Just read the program location back:

    Dim exePath As String = System.Reflection.Assembly.GetEntryAssembly().Location
    Dim drive As String = System.IO.Path.GetPathRoot(exePath)
Hans Passant
Does the 'drive' variable refer to the executed path or to the drive letter?
shmuxel
If the CD drive is D then drive will contain "D:\". Use Path.Combine to create the full path to the directory name.
Hans Passant