Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
Root location
posted

I created a navigation bar.Now i need to add Mycomputer as the root location of the navigation bar and i also need the sub directories

I am new to this infragistic control

My code is as below

private void Form1_Load(object sender, EventArgs e)

{

// The text that WinNavigationBar will use when parsing

this.ultraNavigationBar1.RootLocation.DisplayText = "Local Disk (C:)";

// the full path of a child location (or itself).

this.ultraNavigationBar1.RootLocation.Text = "C";

}

private void ultraNavigationBar1_InitializeLocations(object sender, InitializeLocationsEventArgs e)

{

// Populate an array of DirectoryInfos with the

// subdirectories of the parent location's path.

DirectoryInfo[ dirs = new DirectoryInfo(e.ParentLocation.GetFullPath(FullPathFormat.EditMode) + "\\Anil\\").GetDirectories();

// Loop through each subdirectory...

foreach (DirectoryInfo dir in dirs)

{

// ...add a new location to WinNavigationBar.

// The subdirectory's full path will be the key

// and the name will be the Text.

e.ParentLocation.Locations.Add(dir.FullName, dir.Name);

}

}

private void LoadFilesAndFolders(string path)

{

// Populate an array of DirectoryInfos with the

// subdirectories of the selected location's path.

 

DirectoryInfo[ dirs = new DirectoryInfo(path + "\\").GetDirectories();

// Get the files associated with the selected location.

FileInfo[ files = new DirectoryInfo(path + "\\").GetFiles();

// Clear the previous location’s items from WinListView

this.ultraListView1.Items.Clear();

UltraListViewItem item = null;

// Populate WinListView with folders and files.

foreach (DirectoryInfo dir in dirs)

{

item =
this.ultraListView1.Items.Add(dir.FullName, dir.Name);

item.Tag = dir;

// At this point, you can assign an image

// to the folder items with a line of code

// similar to the following...

//item.Appearance.Image = this.imageListLarge.Images[0];

}

foreach (FileInfo file in files)

{

item =
this.ultraListView1.Items.Add(file.FullName, file.Name);

item.Tag = file;

}

 

 

}

private void ultraNavigationBar1_SelectedLocationChanged(object sender, SelectedLocationChangedEventArgs e)

{

this.LoadFilesAndFolders(e.SelectedLocation.GetFullPath(Infragistics.Win.Misc.FullPathFormat.EditMode));

}

private void ultraListView1_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)

{

if (e.Item.Tag is DirectoryInfo)

{

this.ultraNavigationBar1.NavigateTo(e.Item.Key, true);

}

else if (e.Item.Tag is FileInfo)

{

System.Diagnostics.
Process.Start(e.Item.Key);

}

}

 

I am getting an error in this line

DirectoryInfo[ dirs = new DirectoryInfo(e.ParentLocation.GetFullPath(FullPathFormat.EditMode) + "\\Anil\\").GetDirectories();

as Could not find a part of the path 'C:\Users\Anil\Documents\Visual Studio 2008\Projects\NavigationBarusingInfragistic\NavigationBarusingInfragistic\bin\Debug\C\Anil'.

what modification should i do with the code

Please help me

Parents
No Data
Reply
  • 69832
    Verified Answer
    Offline posted

    1) This line of code: this.ultraNavigationBar1.RootLocation.Text = "C";
    should be changed to: this.ultraNavigationBar1.RootLocation.Text = "C:";

    2) This line of code: DirectoryInfo[ dirs = new DirectoryInfo(e.ParentLocation.GetFullPath(FullPathFormat.EditMode) + "\\Anil\\").GetDirectories();
    should be changed to: DirectoryInfo[ dirs = new DirectoryInfo(e.ParentLocation.GetFullPath(FullPathFormat.EditMode)).GetDirectories();

Children