DEV Community

GroupDocs
GroupDocs

Posted on

2 1

Retrieve Folders Contained in Outlook Data Files using C# .NET API

Application developers can get the list of folders and sub-folders from OST and PST Outlook data files as well as render the messages from these folders to PDF, HTML and Image formats with the help of the latest release of the .NET document rendering API. Also, you can programmatically omit empty columns while rendering Microsoft Excel worksheets within your .NET apps to reduce processing time and optimize memory usage when working with large files using GroupDocs.Viewer for .NET – http://bit.ly/2UNFCDL

Refer to following code examples/snippets for more help on how to perform these tasks inside your applications.

Below code snippet shows how you can retrieve the list of folders:

// Setup GroupDocs.Viewer config
ViewerConfig config = Utilities.GetConfigurations();
// Create image handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
string guid = DocumentName;
// Get Outlook document info
OutlookDocumentInfoContainer documentInfoContainer = imageHandler.GetDocumentInfo(guid) as OutlookDocumentInfoContainer;
foreach (string folderName in documentInfoContainer.Folders)
Console.WriteLine("Folder name: {0}", folderName);

Here's how you can retrieve sub-folders list:

// Setup GroupDocs.Viewer config
ViewerConfig config = Utilities.GetConfigurations();
// Create image handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
string guid = DocumentName;
// Create option object with specified folder name
DocumentInfoOptions options = new DocumentInfoOptions();
options.OutlookOptions.FolderName = "Inbox";
// Get outlook document info
OutlookDocumentInfoContainer documentInfoContainer = imageHandler.GetDocumentInfo(guid, options) as OutlookDocumentInfoContainer;
foreach (string folderName in documentInfoContainer.Folders)
Console.WriteLine("Folder name: {0}", folderName);

Below code snippet demonstrates how an email message from any of the retrieved folders can be rendered as an image:

// Setup GroupDocs.Viewer config
ViewerConfig config = Utilities.GetConfigurations();
// Create image handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
string guid = DocumentName;
// Create image options with specified folder name (use HtmlOptions to render into HTML)
ImageOptions options = new ImageOptions();
options.OutlookOptions.FolderName = "Inbox\\Sub Folder 1";
// Render document into image (List<PageHtml> is returned when rendering into HTML)
List<PageImage> pages = imageHandler.GetPages(guid, options);
foreach (PageImage page in pages)
{
// Save each image at disk
Utilities.SaveAsImage(page.PageNumber + "_" + DocumentName, page.Stream);
}

To render a message as PDF, refer to following code example:

// Setup GroupDocs.Viewer config
ViewerConfig config = Utilities.GetConfigurations();
// Create image handler
ViewerImageHandler imageHandler = new ViewerImageHandler(config);
string guid = DocumentName;
// Create pdf options with specified folder name
PdfFileOptions options = new PdfFileOptions();
options.OutlookOptions.FolderName = "Inbox";
// Get pdf document
FileContainer fileContainer = imageHandler.GetPdfFile(guid, options);
//Save file
Utilities.SaveFile(guid, fileContainer.Stream);

YouTube video tutorials of the GroupDocs API – http://bit.ly/2UKFx3L

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

If you found this post helpful, please leave us a ❤️ or a kind comment!

Got it!