يمكنك استخدام كود يتحقق أولًا من وجود الملف في المسار الأساسي (D:\all\mn.docx) وإذا لم يكن موجودًا، يحاول فتح الملف من الفلاشة (مثلًا H:\all\mn.docx).
إليك الطريقة:
وإذا أردت أن يبحث حتى في D: ضمن حلقة الأقراص:
يمكنك تعديل الكود بحيث يتحقق من كل الأقراص، بما فيها D: .
هكذا:
إليك الطريقة:
PHP كود :
Imports System.IO
Imports System.Diagnostics
Sub OpenWordDocument()
Dim filePathD As String = "D:\all\mn.docx"
Dim filePathH As String = "H:\all\mn.docx"
If File.Exists(filePathD) Then
Process.Start(filePathD)
ElseIf File.Exists(filePathH) Then
Process.Start(filePathH)
Else
MessageBox.Show("الملف غير موجود على القرص D أو الفلاشة H", "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
End If
End Sub
وإذا أردت أن يبحث حتى في D: ضمن حلقة الأقراص:
يمكنك تعديل الكود بحيث يتحقق من كل الأقراص، بما فيها D: .
PHP كود :
Imports System.IO
Imports System.Diagnostics
Sub OpenWordDocument()
For Each drive As DriveInfo In DriveInfo.GetDrives()
If drive.IsReady AndAlso (drive.DriveType = DriveType.Removable OrElse drive.DriveType = DriveType.Fixed) Then
Dim path As String = Path.Combine(drive.Name, "all\mn.docx")
If File.Exists(path) Then
Process.Start(path)
Exit Sub
End If
End If
Next
MessageBox.Show("الملف mn.docx غير موجود في أي قرص.", "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
End Sub
