|
เวลาที่ Build Project ทั้งโหมด Debug หรือ Release ตำแหน่งของไฟล์จะแบ่งออกเป็น
กรณี Windows 64 บิท จะอยู่ที่
"\bin\debug"
"\bin\release"
หรือ Windows 32 บิท
"\bin\x86\debug"
"\bin\x86\release"
สมมุติอ่านค่า Application.StartupPath ได้เป็น
C:\Project VB.Net\ConnectAccessNET\bin\debug
เราจะถอยหลังโดยการตัด \bin\debug ทิ้งออกไป โดยการเปรียบเทียบค่าเพื่อให้เป็น
C:\Project VB.Net\ConnectAccessNET
- ' / --------------------------------------------------------------------------------
- ' / Get my project path
- ' / AppPath = C:\My Project\bin\debug
- ' / Replace "\bin\debug" with ""
- ' / Return : C:\My Project\
- Function MyPath(AppPath As String) As String
- '/ MessageBox.Show(AppPath);
- AppPath = AppPath.ToLower()
- '/ Return Value
- MyPath = AppPath.Replace("\bin\debug", "").Replace("\bin\release", "").Replace("\bin\x86\debug", "")
- '// If not found folder then put the \ (BackSlash) at the end.
- If Right(MyPath, 1) <> "" Then MyPath = MyPath & ""
- End Function
คัดลอกไปที่คลิปบอร์ด
(ข้อผิดพลาดในการแสดงผล เพราะมันไม่โชว์เครื่องหมาย \) แก้ไขบรรทัดก่อน End Function ...
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
การนำไปใช้งาน:
Dim strPathData As String = MyPath(Application.StartupPath) & "ไฟล์ MS ACCESS"
|
|