Thursday, December 21, 2006 1:41 PM
In windows , when we right click on any folder or file, we get properties . In the properties we can see General/Security etc..
Is it possible to get the properties dll in c#?
Thursday, December 21, 2006 7:53 PMWhat exactly do you want? Do you want to open the properties window from a C# application or are you just interesetd in some of the settings?
Thursday, December 21, 2006 7:57 PMModerator
This dialog is created by the Shell. To display the properties dialog for an arbitrary file you'll need to call to the Shell. The Shell function is SHObjectProperties. Use P/Invoke to point it to the file and it'll display the property dialog.
Michael Taylor - 12/21/06
Friday, December 22, 2006 4:13 AM
how to use the property dll for a file or folder while creating a context menu item(like winzip). In folder property menu item, we can see Type, location, file size, created by, contains.. I want to create a similar application..
Friday, December 22, 2006 1:38 PMModerator
I don't follow what you want. If you want to display the properties of a file or folder when a user right-clicks on a context menu then the function mentioned earlier will work. If you are working with multiple files at the same time then use SHMultiFileProperties. If you want to generate the context menu for a file or folder then you have to revert to COM to access the IContextMenu interface of the object. You can then get access to the context menu and the associated commands. If you want to do this from within a compound file (like a ZIP file) then you won't be able to use the shell and will have to code it manually. Can you be more specific about what you are looking for? If possible give the exact situation that you have and the exact situation that you want rather than referring to other application's as examples.
Michael Taylor - 12/22/06
Tuesday, December 26, 2006 5:31 AM
Thanks for the reply.. Before Continuing, Let me wish all Belated Christmas..
I would like to create an application in which it has the folder property items. I would like to have the Type,location,size,contains,created that we see in properties in my own application. How to create such an application?
Tuesday, December 26, 2006 11:18 AM
Tuesday, December 26, 2006 11:46 AM
Is it possible to get the name of the folder which we get when we right click on any folder's properties to a textbox?
Tuesday, December 26, 2006 12:10 PMcan you please explain in more steps what exactly you are trying to do? Because I don't understand what you need.
Tuesday, December 26, 2006 1:02 PM
My application will be like a context file Menu type which appears when the user right clicks on any folder. I need to get the folder's name,type,location, size,contains,created information from that folder which the user right clicks into my application and then upload the folders document into the database
Tuesday, December 26, 2006 2:24 PMModerator
So you have a tree view that displays folders and you want to get some info about the underlying folder when the user clicks on it? If so then it is completely dependent upon how you set up the tree. Each node will need to store some information about the associated folder. You could store the DirectoryInfo structure for the folder but this is probably overkill. Instead I'd just store the folder path in the Tag property.
Now when the user right-clicks the folder you can retrieve the properties by using DirectoryInfo like so:
DirectoryInfo di = new DirectoryInfo(selectedNode.Tag as string);
There is no method in .NET to retrieve the total size of a directory. Part of the reason is that this is a time consuming process. If you want to get the size of the directory then you'll need to enumerate the files and subfolders and add up their sizes. You'll want to consider doing this in a secondary thread (BackgroundWorker) for UI displays as it can take quite a while. Explorer does this same thing. You'll see it load information about a large directory in the background as it enumerates. Here is a method to help you calculate the directory size (it does not handle security permissions so you'll need to add in exception handling).
privatelong GetDirectorySize ( string dir )
long nSize = 0;
foreach (string childDir in Directory.GetDirectories(dir))
nSize += GetDirectorySize(childDir);
}; foreach (string childFile in Directory.GetFiles(dir))
nSize += new FileInfo(childFile).Length;
If you want to display the shell property dialog for the node then it becomes a simple matter of calling SHObjectProperties like so:
SHObjectProperties(Handle, 2, selectedNode.Tag as string, null);
You'll prototype the method as:
private static extern bool SHObjectProperties(IntPtr hwnd, uint dwType, string szObject, string szPage);
Michael Taylor - 12/26/06
Wednesday, December 27, 2006 5:00 AMThank You for the reply. But i dont have a tree view here. Imagine this scenario. In the desktop, we can see folders. when an user right clicks on any folder, the user can see the properties menu item,rite. I am trying to create a similar application which has the items like(folder or file name, Type,size,Location,contains,created). Also i want my application's name to be available in the rightclick popup, when the user right clicks on any folder.
Wednesday, December 27, 2006 5:38 AM
If you could please provide me your email address, i would send u the screen-shot of the design i have in mind. This will help you in understanding what exactly i want.
Wednesday, December 27, 2006 1:13 PMModerator
My e-mail address can be found under my profile. Remove the spam keywords to get the actual e-mail address.
Michael Taylor - 12/27/06