How to create Recent Documents History in C# in WPF Application
Asked Answered
P

6

13

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! :)

Pyroxylin answered 8/3, 2010 at 7:34 Comment(4)
Did you check MRUManager class?Waki
Like I said....I am an amateur coder....please help me understand the MRUManager class and what it does. Thanks.Pyroxylin
Did you check the codeproject article I linked?Waki
Did you see the word WPF in the OP?Blouin
A
10

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>
Agentive answered 12/5, 2010 at 5:51 Comment(5)
What are the JumpList for WinForm?Undersecretary
@kmc Because JumpList (the code shown) displays a list of Most Recent Used documents, you webby ;)Agentive
Maybe i'm missing something, but this just creates a jump list and says to include the Recent category (Which is the default JumpList you get for free anyway). This does nothing for showing the Recent items IN the application?Rodina
This initializes the jump list but doesn't do anything with it. At the very least one must also invoke e.g. AddToRecentCategory() and Apply() whenever a file should be recorded as recent. Additionally, this information is only available in the Windows taskbar, not within the application itself.Centipede
Here is a more complete jump list answer: https://mcmap.net/q/905514/-how-to-add-recently-open-documents-to-the-openrecent-menu-items-in-wpf.Centipede
S
4

This has a pretty nice walk through and sample

http://www.codeproject.com/KB/WPF/RecentFileList.aspx

Its good that it has both an xml file and registry store.

Synonymous answered 14/3, 2011 at 3:24 Comment(0)
W
3

My idea of solving this problem (as a beginner) was to retain all the file paths into a Queue of given maximum capacity and adding them at run-time into a menuItem...

Whereupon answered 2/4, 2012 at 18:50 Comment(0)
P
2

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.

Pelham answered 8/3, 2010 at 8:12 Comment(0)
J
1

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.

Janey answered 19/7, 2010 at 8:35 Comment(0)
K
1

You might be interested in the Writer sample application of the WPF Application Framework (WAF). It shows how to use and implement a recent file list which is shown in the file menu and on the start page.

Kohler answered 22/5, 2011 at 8:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.