I'm trying to utilize the contents of an Outlook 2010 calendar on a web app. For that I set up a WebDAV enabled website on a IIS 7.5/Windows 2008 R2 machine. From Outlook 2010, I published the calendar to the website I set up, and that resulted in a new
.ics file on the website folder.
When I use this code in the example (modified a little bit), I get 2 exceptions, one on OpenSharedItem which says Operation Failed, and another on OpenSharedFolder, which says that the file is not a valid internet calendar file.
string fileName = "filename.ics";
if (!File.Exists(fileName))
Console.WriteLine("File Does NOT Exist");
else
Console.WriteLine("File Exists");
// First try to open the icalendar file as an appointment
// (not a calendar folder).
object item = null;
try
{
Application a = new Application();
item = a.Session.OpenSharedItem(fileName);
Console.WriteLine("open shared item");
}
catch(System.Exception e)//gets thrown
{
Console.WriteLine("Open shared item failed");
Console.WriteLine(e.Message + e.StackTrace);
}
if (item != null)
{
Console.WriteLine("item not null");
// Display the item
OutlookItem olItem = new OutlookItem(item);
olItem.Display();
return;
}
// If unsucessful in opening it as an item,
// try opening it as a folder
Outlook.Folder importedFolder = null;
try
{
Application a = new Application();
importedFolder = a.Session.OpenSharedFolder(fileName, Type.Missing, Type.Missing, Type.Missing) as Outlook.Folder;
Console.WriteLine("open shared folder");
}
catch (System.Exception e)//gets thrown
{
Console.WriteLine("Open shared folder failed");
Console.WriteLine(e.Message + e.StackTrace);
}
// If sucessful, open the folder in a new explorer window
if (importedFolder != null)
{
//never reached
}
greatbear
Member
160 Points
189 Posts
Microsoft.Office.Interop.Outlook error - The file filename.ics is not a valid Internet Calendar f...
Nov 08, 2012 11:47 PM|LINK
I'm trying to utilize the contents of an Outlook 2010 calendar on a web app. For that I set up a WebDAV enabled website on a IIS 7.5/Windows 2008 R2 machine. From Outlook 2010, I published the calendar to the website I set up, and that resulted in a new .ics file on the website folder.
Now, to read/parse the contents of the file, I copied that file over to my VS 2012 machine, which is the same machine where Outlook is installed. I used this example to parse the file: http://msdn.microsoft.com/en-us/library/office/bb644609%28v=office.12%29.aspx
When I use this code in the example (modified a little bit), I get 2 exceptions, one on OpenSharedItem which says Operation Failed, and another on OpenSharedFolder, which says that the file is not a valid internet calendar file.
string fileName = "filename.ics"; if (!File.Exists(fileName)) Console.WriteLine("File Does NOT Exist"); else Console.WriteLine("File Exists"); // First try to open the icalendar file as an appointment // (not a calendar folder). object item = null; try { Application a = new Application(); item = a.Session.OpenSharedItem(fileName); Console.WriteLine("open shared item"); } catch(System.Exception e)//gets thrown { Console.WriteLine("Open shared item failed"); Console.WriteLine(e.Message + e.StackTrace); } if (item != null) { Console.WriteLine("item not null"); // Display the item OutlookItem olItem = new OutlookItem(item); olItem.Display(); return; } // If unsucessful in opening it as an item, // try opening it as a folder Outlook.Folder importedFolder = null; try { Application a = new Application(); importedFolder = a.Session.OpenSharedFolder(fileName, Type.Missing, Type.Missing, Type.Missing) as Outlook.Folder; Console.WriteLine("open shared folder"); } catch (System.Exception e)//gets thrown { Console.WriteLine("Open shared folder failed"); Console.WriteLine(e.Message + e.StackTrace); } // If sucessful, open the folder in a new explorer window if (importedFolder != null) { //never reached }