Hi,
what is the way to get url of system folders such as window , fonts ??
Printable View
Hi,
what is the way to get url of system folders such as window , fonts ??
You can use System.Environment.GetFolderPath to get the directory for special folders, however I am not sure that Fonts is considered a special folder.
For example:
vb Code:
MessageBox.Show(System.Environment.GetFolderPath(Environment.SpecialFolder.System))
Will return your System32 folder.
Yes, use the SpecialDirectories function of the FileIO class.
Edit: The Fonts directory isnt acccessible under this class thoughCode:OpenFileDialog1.InitialDirectory = FileIO.SpecialDirectories.MyDocuments
I did a little reading and it looks like you would have to use the SHGetSpecialFolderLocation API to get the Fonts Folder.
I guess you could just get the Windows directory and append "\Fonts" to it...
Or use the SHGetSpecialFolderLocation API and pass the CSIDL_FONTS constant to it.
I wrote this up as I was curious to see the diffs from VB 6 to VB.NET.
Code:Option Explicit On
Option Strict On
Imports System.Text
Imports System.Runtime.InteropServices
Public Class Form1
Private Const CSIDL_FONTS As Int32 = &H14
<StructLayout(LayoutKind.Sequential)> _
Public Structure SHTEMID
Dim cb As IntPtr
Dim abID As Byte
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure ITEMIDLIST
Dim mkid As SHTEMID
End Structure
<DllImport("shell32.dll", CharSet:=CharSet.Auto, EntryPoint:="SHGetPathFromIDList")> _
Public Shared Function SHGetPathFromIDListW(ByVal pidl As IntPtr, <MarshalAs(UnmanagedType.LPTStr)> ByVal pszPath As StringBuilder) As Boolean
End Function
<DllImport("shell32.dll", CharSet:=CharSet.Auto, EntryPoint:="SHGetSpecialFolderLocation")> _
Public Shared Function SHGetSpecialFolderLocation(ByVal hwnd As IntPtr, ByVal csidl As Int32, ByRef ppidl As ITEMIDLIST) As Int32
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ret As Integer, itm As ITEMIDLIST
ret = SHGetSpecialFolderLocation(Me.Handle, CSIDL_FONTS, itm)
If ret = 0 Then
Dim buff As New StringBuilder(" ", 512)
Dim bret As Boolean
bret = SHGetPathFromIDListW(itm.mkid.cb, buff)
MessageBox.Show(buff.ToString)
End If
End Sub
End Class
what is the way to get windows folder?Quote:
Originally Posted by RobDog888
then i want open that folder , what i must do?
You can just pass the windows clsid const with my previous code but I thought you wanted the Fonts dir?
yes ;)
I think the confusion came from not enough description before my code :D
It can directly get the Fonts directory.
Dear Robert,
Sorry for hacking these post. Where can i found that DllImport Functions.Is there any Offline utiltity avaliable. I tried one from Pinvoke.net,but it is that not effective
Dana
No prob. Its easy to format.
I find that the API Viewer utility is still better then pinvoke.Code:<DllImport("filename", CharSet:=CharSet.Auto, EntryPoint:="name of api")> _
Ohhhhhh. I already have this one.......... But I missed that one.. Now I got this one.