Anyone successfully used this in VB.Net. I've been trying, unsuccessfuly however.
I been using the following:
Public Enum eCSIDL
CSIDL_DESKTOP = 0
CSIDL_INTERNET = &H1
CSIDL_PROGRAMS = &H2
CSIDL_CONTROLS = &H3
CSIDL_PRINTERS = &H4
CSIDL_PERSONAL = &H5
CSIDL_FAVORITES = &H6
CSIDL_STARTUP = &H7
End Enum
Public Const SHGFP_TYPE_CURRENT = &H0
Public Const SHGFP_TYPE_DEFAULT = &H1
Public Const MAX_PATH = 260
Public Const S_OK = 0
Public Const S_FALSE = 1
<DllImport("SHFOLDER.DLL"> _
Public Function _
SHGetFolderPath( _
ByVal hwndOwner As IntPtr, _
ByVal nFolder As eCSIDL, _
ByVal hToken As Int32, _
ByVal dwReserved As Int32, _
ByVal lpszPath As String _
) As Int32
End Function
Private Function GetFolderPath(ByVal nCSIDL As eCSIDL) As String
Dim strPath As String = New String(" "c, 260)
Dim i As Integer
Try
If SHGetFolderPath(Me.Handle, nCSIDL, 0&, _ SHGFP_TYPE_CURRENT, strPath) = S_OK Then
GetFolderPath = Microsoft.VisualBasic.Left(strPath, InStr(strPath, Chr(0)) - 1)
End If
Catch ex As Exception
strPath = ex.Message
End Try
Return strPath
End Function
Dim sPath as String
sPath = GetFolderPath(Gobal.eCSIDL.CSIDL_PERSONAL)
Using CSIDL_PERSONAL should return the path to My Documents. So far all that is returned is an empty string.
I've tried changing the API Declare to use ByRef lpszPath As String instead of ByVal lpszPath As String but it doesn't seem to make any difference in the final result.
Anyone got any ideas on how to make this work?
Thanks,
Promis
I been using the following:
Public Enum eCSIDL
CSIDL_DESKTOP = 0
CSIDL_INTERNET = &H1
CSIDL_PROGRAMS = &H2
CSIDL_CONTROLS = &H3
CSIDL_PRINTERS = &H4
CSIDL_PERSONAL = &H5
CSIDL_FAVORITES = &H6
CSIDL_STARTUP = &H7
End Enum
Public Const SHGFP_TYPE_CURRENT = &H0
Public Const SHGFP_TYPE_DEFAULT = &H1
Public Const MAX_PATH = 260
Public Const S_OK = 0
Public Const S_FALSE = 1
<DllImport("SHFOLDER.DLL"> _
Public Function _
SHGetFolderPath( _
ByVal hwndOwner As IntPtr, _
ByVal nFolder As eCSIDL, _
ByVal hToken As Int32, _
ByVal dwReserved As Int32, _
ByVal lpszPath As String _
) As Int32
End Function
Private Function GetFolderPath(ByVal nCSIDL As eCSIDL) As String
Dim strPath As String = New String(" "c, 260)
Dim i As Integer
Try
If SHGetFolderPath(Me.Handle, nCSIDL, 0&, _ SHGFP_TYPE_CURRENT, strPath) = S_OK Then
GetFolderPath = Microsoft.VisualBasic.Left(strPath, InStr(strPath, Chr(0)) - 1)
End If
Catch ex As Exception
strPath = ex.Message
End Try
Return strPath
End Function
Dim sPath as String
sPath = GetFolderPath(Gobal.eCSIDL.CSIDL_PERSONAL)
Using CSIDL_PERSONAL should return the path to My Documents. So far all that is returned is an empty string.
I've tried changing the API Declare to use ByRef lpszPath As String instead of ByVal lpszPath As String but it doesn't seem to make any difference in the final result.
Anyone got any ideas on how to make this work?
Thanks,
Promis