views:

376

answers:

5

I am making a WPF Application in C# where I need to show the recent documents history (just like it happens in word, excel and even visual studio), showing the list the last 5 or 10 documents opened. I have absolutely no idea as to how I should go about it. Please help. And please be kind and gentle...I am an amatuer coder, and it is tough to digest high-tech talks as of now! :)

+1  A: 

Did you check MRUManager class?

Shoban
Like I said....I am an amateur coder....please help me understand the MRUManager class and what it does. Thanks.
Gagan
Did you check the codeproject article I linked?
Shoban
+2  A: 

You could just keep a list of the documents that the user opens. Store the list when the program exits and load it when the program launches. You could probably store a list of things in the program settings, or you could write it to a file (plain text or xml would work ok).

You'd have to create the submenu for "recent documents" dynamically by keeping a reference to the "recent documents" MenuItem, then adding and removing MenuItems from its Items collection. There's a discussion about that here: Add new menuitem to menu at runtime.

The library that was linked above by Shoban looks like a set of classes that do this for you. But, it's for winforms. If you're using wpf, you might have to write your own (though there are probably pre-made ones out there somewhere), but the winforms one will give you a good starting place.

You can also then create jumplists in win7's taskbar using the Windows API Code Pack for .Net.

Benny Jobigan
A: 

JumpList in WPF4 is awesome. This was all I needed to do:

<Application 
    x:Class="MyApp"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    <Application.Resources>
    </Application.Resources>
    <JumpList.JumpList>
        <JumpList ShowRecentCategory="True"/>
    </JumpList.JumpList>
</Application>
Sergey Aldoukhov
A: 

Sergey Aldoukhov would you please elaborate how did made the recent file menu in wpf application i have also enable the jump list but do not know how to proceed further

jaminator
A: 

Gagan, i have recently made a recent file menu in WPF C# and here is what i did:

-> to enable the jumplist functionality and start menu recent file menu i used the windows API shell routine like this:

[DllImport("shell32.dll")] //shell routine to enable jumplist and recenfiles public static extern void SHAddToRecentDocs( UInt32 uFlags, [MarshalAs(UnmanagedType.LPWStr)] String pv);

and call it like this: SHAddToRecentDocs(0x00000003, mFilePath);

-> Then to display recent file menu i used an xml file, stored recent files in that and parsed and displayed recent file in the menu.

jaminator