ok so i found a way to do what i needed and that was:
The server loads files and folders into a Treeview it then saves the tree as an xml file and sends it to the clients at logon.
i have added the code i used to solve this i hope it helps.
ps. if the way im doing it is wrong then plz let me know ty
code that the server runs to make the treeveiw and save the xml:
Public Sub kcTree2XML(ByVal XMLFilePath As String, ByVal kcTreeview As TreeView)
Dim XMLDoc As New Xml.XmlDocument
Dim RootNode As TreeNode
Dim NewXMLNode As Xml.XmlNode
Dim XMLAttribute As Xml.XmlAttribute
XMLDoc.LoadXml(("<?xml version='1.0' ?>" & _
"<XMLTreeView>" & _
"</XMLTreeView>"))
For Each RootNode In kcTreeview.Nodes
NewXMLNode = XMLDoc.CreateNode(Xml.XmlNodeType.Element, "Node", "Node", "")
XMLAttribute = XMLDoc.CreateAttribute("name")
XMLAttribute.Value = RootNode.Text
NewXMLNode.Attributes.Append(XMLAttribute)
XMLDoc.DocumentElement.AppendChild(NewXMLNode)
SaveChildNodes(NewXMLNode, RootNode, XMLDoc)
Next
XMLDoc.Save(XMLFilePath)
End Sub
Private Sub SaveChildNodes(ByVal XMLNode As Xml.XmlNode, ByVal ParentNode As TreeNode, ByVal XMLDoc As Xml.XmlDocument)
Dim ChildNode As TreeNode
Dim NewXMLNode As Xml.XmlNode
Dim XMLAttribute As Xml.XmlAttribute
For Each ChildNode In ParentNode.Nodes
NewXMLNode = XMLDoc.CreateNode(Xml.XmlNodeType.Element, "Node", "Node", "")
XMLAttribute = XMLDoc.CreateAttribute("name")
XMLAttribute.Value = ChildNode.Text
NewXMLNode.Attributes.Append(XMLAttribute)
XMLNode.AppendChild(NewXMLNode)
SaveChildNodes(NewXMLNode, ChildNode, XMLDoc)
Next
End Sub
Public Sub DisplayTree(ByVal DirTree As String, ByVal stnode As TreeNode)
Dim NameDir As IO.DirectoryInfo
Dim MyNode, MyNode1 As TreeNode
If IO.Directory.Exists(DirTree) Then
For Each MyDir As String In IO.Directory.GetDirectories(DirTree)
NameDir = New IO.DirectoryInfo(mydir)
MyNode = stnode.Nodes.Add(NameDir.Name)
MyNode.ImageIndex = iconIn
MyNode.SelectedImageIndex = iconIn
If IO.Directory.Exists(NameDir.ToString) Then
For Each MyDir1 As String In IO.Directory.GetFiles(NameDir.ToString)
NameDir = New IO.DirectoryInfo(MyDir1)
MyNode1 = MyNode.Nodes.Add(NameDir.Name)
MyNode1.Tag = MyDir1
MyNode1.ImageIndex = iconIn
MyNode1.SelectedImageIndex = iconIn
Next
End If
If IO.Directory.Exists(MyDir) Then
Call DisplayTree(MyDir, MyNode)
End If
Next
Dim MyNode2 As TreeNode
For Each MyDir As String In IO.Directory.GetFiles(DirTree)
NameDir = New IO.DirectoryInfo(MyDir)
MyNode2 = stnode.Nodes.Add(NameDir.Name)
MyNode2.Tag = MyDir
MyNode2.ImageIndex = iconIn
MyNode2.SelectedImageIndex = iconIn
Next
End If
End Sub
The client loads the xml and adds an icon to the node.
(the clsicon class is from devX same with the tree2XML function and XML2tree fucntion)
code to load the xml:
Dim iconIn As Integer
Private nIndex = 2
Public Function kcXML2Tree(ByVal XMLFilepath As String, ByVal kcTreeview As TreeView)
Dim XMLDoc As New Xml.XmlDocument
Dim XMLNode As Xml.XmlNode
Dim ParentNode As TreeNode
If kcTreeview Is Nothing Then
Throw New ArgumentNullException("TreeView")
End If
Try
XMLDoc.Load(XMLFilepath)
Catch e As Exception
Throw New Exception(e.Message)
End Try
For Each XMLNode In XMLDoc.DocumentElement.ChildNodes
AddIcon(XMLNode.Attributes(0).Value)
kcTreeview.ImageList = frmMain.ImageList4
ParentNode = kcTreeview.Nodes.Add(XMLNode.Attributes(0).Value, XMLNode.Attributes(0).Value)
If XMLNode.ChildNodes.Count > 0 Then
AddChildNodes(XMLNode, ParentNode)
End If
Next
End Function
Public Sub AddIcon(ByVal Namedir As String)
Dim Test As New clsIcon()
Dim iconimg = clsIcon.GetDefaultIcon(Namedir, clsIcon.IconSize.SmallIcon)
frmMain.ImageList4.Images.Add(iconimg)
iconIn = nIndex
nIndex = nIndex + 1
End Sub
Private Sub AddChildNodes(ByVal XMLNode As Xml.XmlNode, ByVal ParentNode As TreeNode)
Dim ChildXMLNode As Xml.XmlNode
Dim NewNode As TreeNode
For Each ChildXMLNode In XMLNode.ChildNodes
AddIcon(ChildXMLNode.Attributes(0).Value)
NewNode = ParentNode.Nodes.Add(ChildXMLNode.Attributes(0).Value, ChildXMLNode.Attributes(0).Value, iconIn, iconIn)
NewNode.Parent.ImageIndex = 1
NewNode.Parent.SelectedImageIndex = 1
If ChildXMLNode.ChildNodes.Count > 0 Then
AddChildNodes(ChildXMLNode, NewNode)
End If
Next
End Sub
and now for the system icon class but it does not work with folders so i had to add an icon for that to the image list
'=====================================================================================
' clsIcon
' class to work with icons
'=====================================================================================
' Created By: Marc Cramer
' Published Date: 12/31/2002
' Legal Copyright: Marc Cramer © 12/31/2002
'=====================================================================================
' Adapted From...
' Author: spotchannel (spotchannel@hotmail.com)
' Website: forum post at http://www.devcity.net/forums/topic.asp?tid=7422
'=====================================================================================
Imports System
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Class clsIcon
'=====================================================================================
' Enumerations
'=====================================================================================
<Flags()> Private Enum SHGFI
SmallIcon = &H1
LargeIcon = &H0
Icon = &H100
DisplayName = &H200
Typename = &H400
SysIconIndex = &H4000
UseFileAttributes = &H10
End Enum
Public Enum IconSize
SmallIcon = 1
LargeIcon = 0
End Enum
'=====================================================================================
' Structures
'=====================================================================================
<StructLayout(LayoutKind.Sequential)> _
Private Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
<MarshalAs(UnmanagedType.LPStr, SizeConst:=260)> Public szDisplayName As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=80)> Public szTypeName As String
Public Sub New(ByVal B As Boolean)
hIcon = IntPtr.Zero
iIcon = 0
dwAttributes = 0
szDisplayName = vbNullString
szTypeName = vbNullString
End Sub
End Structure
'=====================================================================================
' API Calls
'=====================================================================================
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlagsn As SHGFI) As Integer
'=====================================================================================
' Functions and Procedures...
'=====================================================================================
Public Shared Function GetDefaultIcon(ByVal Path As String, Optional ByVal IconSize As IconSize = IconSize.SmallIcon, Optional ByVal SaveIconPath As String = "") As Icon
Dim info As New SHFILEINFO(True)
Dim cbSizeInfo As Integer = Marshal.SizeOf(info)
Dim flags As SHGFI = SHGFI.Icon Or SHGFI.UseFileAttributes
flags = flags + IconSize
SHGetFileInfo(Path, 256, info, cbSizeInfo, flags)
GetDefaultIcon = Icon.FromHandle(info.hIcon)
If SaveIconPath <> "" Then
Dim FileStream As New IO.FileStream(SaveIconPath, IO.FileMode.Create)
GetDefaultIcon.Save(FileStream)
FileStream.Close()
End If
End Function 'GetDefaultIcon(ByVal Path As String, Optional ByVal IconSize As IconSize = IconSize.SmallIcon, Optional ByVal SaveIconPath As String = "") As Icon
'=====================================================================================
Public Shared Function ImageToIcon(ByVal SourceImage As Image) As Icon
' converts an image into an icon
Dim TempBitmap As New Bitmap(SourceImage)
ImageToIcon = Icon.FromHandle(TempBitmap.GetHicon())
TempBitmap.Dispose()
End Function 'ImageToIcon(ByVal SourceImage As Image) As Icon
'=====================================================================================
End Class