Create a customized folder

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi everybody :)
I wanna create a folder in My Documents, named "My Information" for example!
And customize its ICON by placing a "Desktop.ini" file into that.
So I wrote this code which works perfect, but I don't know why it does not show the ICON as expected :(
Visual Basic:
'Create Directory
If Not My.Computer.FileSystem.DirectoryExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") Then
    System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information")
End If
'Create File
Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application"
If Not My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") Then
    My.Computer.FileSystem.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini", FileContent, False)
End If
Dim FileDetail As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini")
FileDetail.Attributes = IO.FileAttributes.Hidden + IO.FileAttributes.System
 
Hi PlausiblyDamp,
Thank you very much for your tip.
However, it won't work :(
I really don't know what should I do.
Even if I use Windows to Customize this folder for me, it will create the same file as me!
When Windows creates it, it works! :confused:
Please help me :(
 
Visual Basic:
Declare Auto Function PathMakeSystemFolder Lib "shlwapi.dll" Alias "PathMakeSystemFolder" (ByVal pszPath As String) As Integer
Call the above function passing the folder path as an argument - that sorts out the attributes correctly.
 
Well, thanks :)
This code must work now, but it's not :(
Visual Basic:
    Declare Auto Function PathMakeSystemFolder Lib "shlwapi.dll" Alias "PathMakeSystemFolder" (ByVal pszPath As String) As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Create Directory
        If Not My.Computer.FileSystem.DirectoryExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") Then
            System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information")
        End If
        PathMakeSystemFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information")
        'Create File
        Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application"
        If Not My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") Then
            My.Computer.FileSystem.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini", FileContent, False)
        End If
        Dim FileDetail As IO.FileInfo = My.Computer.FileSystem.GetFileInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini")
        FileDetail.Attributes = IO.FileAttributes.Hidden + IO.FileAttributes.System
    End Sub
 
Try removing the line
Visual Basic:
FileDetail.Attributes = IO.FileAttributes.Hidden + IO.FileAttributes.System
from the end as it might reseting the attributes set by PathMakeSystemFolder call.
 
Hi,
Thank you very much for your help :)
So this final code still does not work on XP:
Visual Basic:
    Declare Auto Function PathMakeSystemFolder Lib "shlwapi.dll" Alias "PathMakeSystemFolder" (ByVal pszPath As String) As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Create Directory
        If Not My.Computer.FileSystem.DirectoryExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information") Then
            System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information")
        End If

        'Create File
        Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application"
        If Not My.Computer.FileSystem.FileExists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini") Then
            My.Computer.FileSystem.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information\Desktop.ini", FileContent, False)
        End If

        PathMakeSystemFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\My Information")
    End Sub
:(
 
No idea then, just tried it on my pc and other than changing the path in the line
Visual Basic:
Dim FileContent As String = "[.ShellClassInfo]" + vbNewLine + "IconFile=%ProgramFiles%\Company\Product\Program.exe" + vbNewLine + "IconIndex=0" + vbNewLine + "InfoTip=Information collected using our application"
to point to an executable that exists on my hard drive it worked perfectly. I am running windows 7 but that shouldn't make a difference as the API has been in existence since NT 4 with IE 4!
 
Back
Top