Récupérer ce qui est écrit dans la console dans un fichier texte
Bonjour,
J'aimerais créer un fichier texte qui contient tout ce qui est écrit dans la console quand j'exécute le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn1
{
class Program
{
static void Main(string[] args)
{
Sample sample = new Sample();
sample.EnumerateFoldersInDefaultStore();
Console.WriteLine();
Console.WriteLine("Fin du programme. Taper n'importe quelle touche pour quitter...");
Console.ReadKey();
}
}
class Sample
{
Outlook.Application GetApplicationObject()
{
Outlook.Application application = null;
// Check whether there is an Outlook process running.
if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
// If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
}
else
{
// If not, create a new instance of Outlook and sign in to the default profile.
application = new Outlook.Application();
Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
nameSpace.Logon("", "", Missing.Value, Missing.Value);
nameSpace = null;
}
// Return the Outlook Application object.
return application;
}
public void EnumerateFoldersInDefaultStore()
{
Outlook.Application application = GetApplicationObject();
Outlook.Folder root =
application.Session.
DefaultStore.GetRootFolder() as Outlook.Folder;
EnumerateFolders(root);
}
// Uses recursion to enumerate Outlook subfolders.
private void EnumerateFolders(Outlook.Folder folder)
{
Outlook.Folders childFolders =
folder.Folders;
if (childFolders.Count > 0)
{
foreach (Outlook.Folder childFolder in childFolders)
{
// Write the folder path.
Debug.WriteLine(childFolder.FolderPath);
Console.WriteLine(childFolder.FolderPath);
// Call EnumerateFolders using childFolder.
EnumerateFolders(childFolder);
}
}
}
}
} |
Quelqu'un sait comment faire ?