TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jaspreet Singh
NA
20
3.8k
Unhandled exception. System.IO.FileNotFoundException: Could
Oct 23 2019 5:49 AM
Hello Team,
I am getting the following error messsage while executing the following code:-
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0
Here is my Code:-
using System;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Outlook;
using Microsoft.Office365.OutlookServices;
namespace FunctionProject
{
class Program
{
static void Main(string[] args)
{
ReadMailItems();
}
private static void ReadMailItems()
{
Application outlookApplication = null;
NameSpace outlookNamespace = null;
MAPIFolder inboxFolder = null;
Items mailItems = null;
try
{
outlookApplication = new Application();
outlookNamespace = outlookApplication.GetNamespace("MAPI");
inboxFolder = outlookNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
mailItems = inboxFolder.Items;
foreach (MailItem item in mailItems)
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("From: " + item.SenderEmailAddress);
stringBuilder.AppendLine("To: " + item.To);
stringBuilder.AppendLine("CC: " + item.CC);
stringBuilder.AppendLine("");
stringBuilder.AppendLine("Subject: " + item.Subject);
stringBuilder.AppendLine(item.Body);
Console.WriteLine(stringBuilder);
Marshal.ReleaseComObject(item);
}
}
catch (System.Exception ex) { throw ex; }
finally
{
ReleaseComObject(mailItems);
ReleaseComObject(inboxFolder);
ReleaseComObject(outlookNamespace);
ReleaseComObject(outlookApplication);
}
}
private static void ReleaseComObject(object obj)
{
if (obj != null)
{
Marshal.ReleaseComObject(obj);
obj = null;
}
}
}
}
Reply
Answers (
1
)
Why does the Form_Paint event run continuously and only draw
Cannot implicitly convert type long to bool