|
Thanks i just need this ^^
|
|
|
|
|
This component is simple and efficient, no flourish, just what I needed in my app.
However, Shell32 Intefracing was a REAL Pain ! (Why this choice over Plain'old IO ?)
All in all, here is the code I've added in order to open the explorer in a default custom folder :
public void SetDefaultFolder(String folderPath)
{
string[] folders = folderPath.Split('\\');
Shell32.ShellClass shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.NameSpace(Win32API.ShellFolder.MyComputer);
for (int i = 0; i < folders.Length; i++)
folder = getSubFolder(folder, folders[i]);
SetListViewItems(folder);
}
private Shell32.Folder getSubFolder(Shell32.Folder folder, string subfolderName)
{
foreach(Shell32.FolderItem folderItem in folder.Items())
{
if (folderItem.Name.Contains(subfolderName))
return (Shell32.Folder)folderItem.GetFolder;
}
throw new Exception("Specified Default Folder Not Found");
}
Usage :
private void Form1_Load(object sender, System.EventArgs e)
{
fileSystemListView1.SetDefaultFolder(@"E:\DATA\LOGS");
fileSystemListView1.Initialize();
}
|
|
|
|
|
Tried to load the project in VS2005 but it's not working.. the icons do not appear on the list view.
|
|
|
|
|
Moved the line and it works!! Great!
|
|
|
|
|
Hello,
since I Upgrade my Project (inkl. the control) to .Net 2.0 I didn't get any Icons.
What's wrong after upgrading?
When I debugging the code, I see on:
item.ImageIndex = _smallImageList.IconIndex(folderItem.Path, true);
getting an Index, but the Icon wouldn't show.
How can I fix this Problem?
Thanks.
|
|
|
|
|
Oh Sorry,
I didn't see the post visual studio .net 2005 beta before. So the problem is fix.
Thanks.
|
|
|
|
|
How do I get the filename(s) of the selected files?
I'm using VS2005 C#. I can get the directory name (browser.SelectedItem.Path) but I can't find the way to get the selected item filename. The browser variable is a FileBroswer.Browser type that I placed in the GUI.
Thanks for any help.... Caleb
|
|
|
|
|
I'd like to debug this project step by step to understand it ,
but the project binding information can not be found so it is treated as not under source control.
if there is something to do ,to run this project like normal one please help me.
|
|
|
|
|
Hi,
I didn't play around this control since i posted it and I don't have Visual Studio .NET 2003 installed to test it but i remember that it was always a bit painful to remove VSS bindings in VS 2003. Have you try to remobe the Read-only flag attribute from the files before opening the project?
Regards
-Jonathan
|
|
|
|
|
How can I make this display hidden folders?
|
|
|
|
|
In order to show hidden folders, replace the line
Shell32.FolderItems folderItems = folder.Items();
with
Shell32.FolderItems3 folderItems = (Shell32.FolderItems3)folder.Items();
int SHCONTF_INCLUDEHIDDEN = 128;
int SHCONTF_FOLDERS = 32;
int SHCONTF_NONFOLDERS = 64;
folderItems.Filter(SHCONTF_INCLUDEHIDDEN | SHCONTF_NONFOLDERS | SHCONTF_FOLDERS, "*");
Jos
|
|
|
|
|
If you simply change the "Sorting" property to be "Ascending" or "Descending", you will find all the system icons are lost when you run the program.
Replace the file FileSystemListView.cs with this one:
http://www.stanford.edu/~yuanyuan/public/FileSystemListView.cs
and compile the control again. You should get proper sorting now.
The new source also contains fix for displaying pdf & zip files.
Do a windiff to see where the actual changes are.
|
|
|
|
|
Could this version be reposted since the link no longer works?
|
|
|
|
|
I think there is a problem with the Shell32.ShellSpecialFolderConstants in the Win32API.cs code. I get the following exception when I compile the FileSystemListViewDemo project code, run it, and double click on first "My Computer", "Administrator's Documents" (I log in as Administrator, this is a system shortcut for My Documents), then double click on any folder in this view (besides the parent .. folder).
It occurs on line 397 of FileSystemListView.cs.
************** Exception Text **************
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: '-1' is not a valid value for 'displayIndex'.
at System.Windows.Forms.ListViewItemCollection.get_Item(Int32 displayIndex)
at LivingObjects.Windows.Forms.FileSystemListView.AddParentItem(Folder folder)
at LivingObjects.Windows.Forms.FileSystemListView.SetListViewItems(Folder folder)
at LivingObjects.Windows.Forms.FileSystemListView.FileSystemListView_DoubleClick(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
My assembly info:
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
FileSystemListViewDemo
Assembly Version: 1.0.2054.28849
Win32 Version: 1.0.2054.28849
CodeBase: file:///C:/Programming/VS/Danny/FileSystemListViewDemo/bin/Release/FileSystemListViewDemo.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
LivingObjects
Assembly Version: 0.9.2054.28849
Win32 Version: 0.9.2054.28849
CodeBase: file:///C:/Programming/VS/Danny/FileSystemListViewDemo/bin/Release/LivingObjects.DLL
----------------------------------------
Interop.Shell32
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Programming/VS/Danny/FileSystemListViewDemo/bin/Release/Interop.Shell32.DLL
----------------------------------------
CustomMarshalers
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/windows/assembly/gac/custommarshalers/1.0.5000.0__b03f5f7f11d50a3a/custommarshalers.dll
----------------------------------------
|
|
|
|
|
just in case anybody's interested, here's some code you can use in your application if you add a right-click context menu to the fileSystemListView1 control:
they work really well in conjunction with Chris Hambleton's DisplayFolder routine (to refresh the view):
private void menuLocalRename_Click(object sender, System.EventArgs e)
{
try
{
if ( fileSystemListView1.SelectedItems.Count > 0 )
{
if ( fileSystemListView1.SelectedItems[0].GetType().Name.ToString() == "FileListViewItem" )
{
FileListViewItem file = fileSystemListView1.SelectedFileItems[0];
// use nfo to get full filename
FileInfo nfo = file.FileInfo;
//get clean directory name of file to be deleted
FileInfo fi = new FileInfo(nfo.FullName.ToString());
InputBoxResult newFileName = InputBox.Show("Rename File To ","File Rename",fi.Name,1499,1065);
if ( newFileName.ReturnCode == DialogResult.OK )
{
if ( File.Exists(fi.DirectoryName + "\\" + newFileName.Text) == false )
{
File.Move(nfo.FullName.ToString(), fi.DirectoryName + "\\" + newFileName.Text);
fileSystemListView1.DisplayFolder(fi.DirectoryName);
}
else
{
MessageBox.Show("Rename *To* Filename Already Exists");
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuLocalDelete_Click(object sender, System.EventArgs e)
{
try
{
if ( fileSystemListView1.SelectedItems.Count > 0 )
{
if ( fileSystemListView1.SelectedItems[0].GetType().Name.ToString() == "FileListViewItem" )
{
if (MessageBox.Show ("Are you sure you want to delete this file? ", "Delete Local File",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
FileListViewItem file = fileSystemListView1.SelectedFileItems[0];
FileInfo nfo = file.FileInfo;
//get clean directory name of file to be deleted
FileInfo fi = new FileInfo(nfo.FullName.ToString());
//now delete it
if ( File.Exists(nfo.FullName.ToString()) == true )
{
File.Delete(nfo.FullName.ToString());
}
else
{
MessageBox.Show("File Does Not Exist.");
}
//now refresh the explorer listing of that folder
fileSystemListView1.DisplayFolder(fi.DirectoryName);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuLocalCreateDir_Click(object sender, System.EventArgs e)
{
try
{
InputBoxResult dir = InputBox.Show("Directory Name ","Create Directory","",1499,1065);
if ( dir.ReturnCode == DialogResult.OK )
{
FolderListViewItem folder = checked ((FolderListViewItem) fileSystemListView1.Items[0]);
DirectoryInfo nfo = folder.DirectoryInfo;
if (Directory.Exists(nfo.FullName.ToString() + "\\" + dir.Text) == false )
{
Directory.CreateDirectory(nfo.FullName.ToString() + "\\" + dir.Text);
//now refresh the explorer listing of that folder
fileSystemListView1.DisplayFolder(nfo.FullName.ToString());
}
else
{
MessageBox.Show("Directory Already Exists");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuLocalDeleteDir_Click(object sender, System.EventArgs e)
{
try
{
if ( fileSystemListView1.SelectedItems.Count > 0 )
{
if ( fileSystemListView1.SelectedItems[0].GetType().Name.ToString() == "FolderListViewItem" )
{
FolderListViewItem folder = checked ((FolderListViewItem) fileSystemListView1.SelectedItems[0]);
//get folder info for selected folder
DirectoryInfo nfo = folder.DirectoryInfo;
if (MessageBox.Show ("Are you sure you want to delete this directory? ", "Delete Local File",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
if (Directory.Exists(nfo.FullName.ToString()) == true )
{
//delete the directory
Directory.Delete(nfo.FullName.ToString(), true);
//refresh current directory
fileSystemListView1.DisplayFolder(nfo.Parent.FullName.ToString());
}
else
{
MessageBox.Show("Directory Does Not Exist");
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
hope it helps-
Kenneth
|
|
|
|
|
I was always forgetting which folder I was in since the view only shows the ..(parentfolder) at the top - so I cloned that code and produced this routine to add .(currentfolder)
///
/// Add a ListViewItem in the ListView corresponding to the Current Folder
/// so you can easily tell where you are.
///
/// <param name="folder" />
private void AddCurrentItem(Shell32.Folder folder)
{
Shell32.FolderItems folderItems;
string currentName = "";
//The specified folder has a Parent
if(folder.ParentFolder != null)
{
//We need to find a FolderItem object corresponding
//to the Parent. There is no known straight way of doing
//this excepting looping though all the Folder items
//the Parent contains until we find the corresponding
//instance.
folderItems = folder.ParentFolder.Items();
foreach(Shell32.FolderItem folderItem in folderItems)
{
//We find it !
if(folderItem.Name == folder.Title)
{
AddItem(folderItem);
currentName = folderItem.Name;
break;
}
}
}
else //The parent is the desktop
{
//Get a reference on the Desktop Folder
Shell32.Shell shell32 = new Shell32.ShellClass();
Shell32.Folder desktopFolder = shell32.NameSpace(Win32API.ShellFolder.DesktopDirectory);
folderItems = desktopFolder.ParentFolder.Items();
//We need a FolderItem instance corresponding to the Desktop
//but we cannot obtain it directly, so loop though it's Parent
//until we get it.
foreach(Shell32.FolderItem folderItem in folderItems)
{
if(folderItem.Name == desktopFolder.Title)
{
AddItem(folderItem);
currentName = folderItem.Name;
break;
}
}
}
//Overwrite the default appearance of the Added ListViewItem
((ExplorerListViewItem)(this.Items[Items.Count - 1])).SubItemName = ". (" + currentName + ")";
((ExplorerListViewItem)(this.Items[Items.Count - 1])).SubItemTypeName = "Current Folder";
((ExplorerListViewItem)(this.Items[Items.Count - 1])).SubItemModifiedDate = "";
((ExplorerListViewItem)(this.Items[Items.Count - 1])).SubItemSize = "";
}
it looks like crap pasted in here, but you should be able to just copy and paste it into the code.
just call it from the SetListViewItems routine, just before the call to AddParentItem(folder).. so it would look like this:
AddCurrentItem(folder); <-- new
if(AllowParentFolderSelection) <--existing
AddParentItem(folder); <--existing
also.. speaking of the SetListViewItems routine.. i changed the following code to display the missing files people were talking about (zip's, pdf's, etc):
change from:
if((folderItem.IsFileSystem || folderItem.IsFolder) && !folderItem.IsBrowsable && folderItem.Name != "Control Panel")
change to:
if ( folderItem.Name != "My Network Places" && folderItem.Name != "Control Panel" )
(i'm skipping My Network Places because it's got issues..)
but be warned though that if you've added code to launch files by double-clicking, not all of these new ones will open.. you may get errors, bad paths, etc.
also, for some reason some zips will let you browse them and some will crash.. it seems similar to the icon issue with "my network places".. but i can't find a rhyme or reason - if anybody knows, please let me know-
hope it helps-
Kenneth
|
|
|
|
|
update:
if you dont mind a default icon being used when it cant find the real one, you can do the following and quit getting the icon error messages, as well as showing ALL files/folders:
remove this if statement from FileSystemListView - SetListViewItems - altogether - this way it'll show everything-
if((folderItem.IsFileSystem || folderItem.IsFolder) && !folderItem.IsBrowsable && folderItem.Name != "Control Panel")
then in SystemImageList - IconIndex - comment-out this line:
System.Diagnostics.Debug.Assert((!retVal.Equals(IntPtr.Zero)),"Failed to get icon index");
and you can play with the next line -
return 0;
trying different numbers to change the default icon it'll use when it can't find the right one. i just left it at 0 - and everything works fine. you can browse all zips and browse my network places and everything with no problems..
if you figure out how to really fix the icon issue, let me know-
Kenneth
|
|
|
|
|
---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
Failed to get icon index
at SystemImageList.IconIndex(String fileName, Boolean forceLoadFromDisk, ShellIconStateConstants iconState) c:\Projects\JagExpress\ClientApp\samples\FileSystemListView_src\LivingObjects\Windows\Forms\SystemImageList.cs(775)
at SystemImageList.IconIndex(String fileName, Boolean forceLoadFromDisk) c:\Projects\JagExpress\ClientApp\samples\FileSystemListView_src\LivingObjects\Windows\Forms\SystemImageList.cs(722)
at FileSystemListView.AddItem(FolderItem folderItem) c:\projects\jagexpress\clientapp\samples\filesystemlistview_src\livingobjects\windows\forms\filesystemlistview.cs(420)
at FileSystemListView.SetListViewItems(Folder folder) c:\projects\jagexpress\clientapp\samples\filesystemlistview_src\livingobjects\windows\forms\filesystemlistview.cs(322)
at FileSystemListView.FileSystemListView_DoubleClick(Object sender, EventArgs e) c:\projects\jagexpress\clientapp\samples\filesystemlistview_src\livingobjects\windows\forms\filesystemlistview.cs(277)
at Control.OnDoubleClick(EventArgs e)
at ListView.WndProc(Message& m)
at ControlNativeWindow.OnMessage(Message& m)
at ControlNativeWindow.WndProc(Message& m)
at NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Application.Run(Form mainForm)
at Form1.Main() c:\projects\jagexpress\clientapp\samples\filesystemlistview_src\filesystemlistviewdemo\form1.cs(92)
---------------------------
Abort Retry Ignore
---------------------------
|
|
|
|
|
In the same directory I putted 3 files, a DOC, a ZIP and a PDF but there's only the DOC that appear...
|
|
|
|
|
In SetListViewItems() method comment these lines in the ForEach loop :
|
|
|
|
|
Hi,
I don't know if the control already give a function like the one I'll give now, but if it's that case, just tell me.
public void RunSelectedFileItems()
{
if (this.SelectedFileCount > 0)
{
System.Diagnostics.Process proc;
foreach(LivingObjects.Windows.Forms.FileListViewItem file in this.SelectedFileItems)
{
proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = file.FileInfo.DirectoryName + "\\" + file.Text;
proc.Start();
}
}
}
private void fileSystemListView1_ItemActivate(object sender, System.EventArgs e)
{
try
{
this.fileSystemListView1.RunSelectedFileItems();
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
Any one implmeted this in vb.net I mean written the entire code in vb.net?
If so can you post it thnaks
|
|
|
|
|
Hi
I managed to convert Furty's FolderTreeView to vb.net with extension of a ListView like in windows explorer. It even check for duplicate icons. Problem starts when there are many files or folder under the selected folder (selected path). It takes all the resources....
So I try now to implement it with the help of this article (...which again requires converting to vb.net), and hope that the System ImageList will solve the resource problem.
If someone already implement it in VB.Net, could you please e-mail me the source (eelises@yahoo.com).
I'll let you know once it works for me.
Thanks guys for the invaluable help!
:::::::::::::::::::::::::::
OMG!! They killed Kenny!
You B------s!!!
:::::::::::::::::::::::::::
|
|
|
|
|
If I build the project with VS.NET 2005 Beta, the icons don't show up when I run the sample program. Anyone know how to fix this?
|
|
|
|
|
I've been struggling with this too. Creating a UserControl in VS.NET 2003 and referencing the dll in C# 2005 Beta still causes the same problem.
I've had no luck solving it.
Cheers,
Paul Wilson
|
|
|
|