• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Asp.Net - Code Hangs...

Can Someone help me out on why this wont work??

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Reflection; //for missing .value

namespace OutlookCalendar
      /// <summary>
      /// Summary description for WebForm1.
      /// </summary>
      public class WebForm1 : System.Web.UI.Page
            protected System.Web.UI.WebControls.CheckBox CheckBox1;
            protected System.Web.UI.WebControls.CheckBox CheckBox2;
            protected System.Web.UI.WebControls.CheckBox CheckBox3;
            protected System.Web.UI.WebControls.CheckBox CheckBox4;
            protected System.Web.UI.WebControls.TextBox TextBox1;
            protected System.Web.UI.WebControls.TextBox TextBox2;
            protected System.Web.UI.WebControls.TextBox TextBox3;
            protected System.Web.UI.WebControls.TextBox TextBox4;
            protected System.Web.UI.WebControls.Calendar Calendar1;
            private void Page_Load(object sender, System.EventArgs e)
                  // Create an Outlook application.
                  Outlook.Application oApp = new Outlook.Application();

                  // Get the Mapi NameSpace and the Logon.
                  Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");

                  // Log on using dialog to choose a profile.
                  oNS.Logon(Missing.Value, Missing.Value, true, true);

                  // Alternate Logon using specific profile
                  // TODO: Change the profile name where it is appropriate.
                  //oNS.Logon("YourValidProfile", Missing.Value, false, true);

                  // Get the Calendar folder.
                  Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

                  // Get the Items collection in the folder.
                  Outlook.Items  oItems = (Outlook.Items)oCalendar.Items;
                  Console.WriteLine("Total Items (unrestricted): " + oItems.Count);

                  //Include all occurrences of recurring items, and then sort them.
                  oItems.Sort ("[Start]", false);
                  oItems.IncludeRecurrences = true;

                  // Define the string for the search criteria.
                  String sCriteria;

                  // Set the criteria for the Date fields.
                  sCriteria = "[Start] <= '04/01/2006 08:00 AM' and [End] >= '04/30/2006 11:00 PM'";

                  // Set the criteria for a string field.
                  // sCriteria = "[Subject] = 'Weekly recurring meeting'";

                  // Set the criteria for a numeric field.
                  // Look for meetings that have not been responded to.
                  // sCriteria = "[ResponseStatus] = " + (Int32)Outlook.OlResponseStatus.olResponseNotResponded)

                  // Use the Restrict method to reduce the number of items to process.
                  Outlook.Items oRestrictedItems = oItems.Restrict(sCriteria);
                  oRestrictedItems.Sort ("[Start]", false);
                  oRestrictedItems.IncludeRecurrences = true;

                  Console.WriteLine("Total Items Unrestricted : " + oRestrictedItems.Count);

                  Outlook.AppointmentItem oAppointment;

                  //Get each item until item is null.
                  Outlook.AppointmentItem oAppt;
                  oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetFirst();
                  while (oAppt != null)
                        // Console.WriteLine(i.ToString());
                        Console.WriteLine("  Subject: " + oAppt.Subject.ToString());
                        Console.WriteLine("  Start time: " + oAppt.Start.ToString());
                        Console.WriteLine("  End time: " + oAppt.End.ToString());
                        Console.WriteLine("  Occurrences: " + oAppt.RecurrenceState.ToString());
                        oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetNext();

                  // Use the Find method to get single match.
                  sCriteria = "[Start] >= '04/01/2006'";
                  Console.WriteLine("Criteria: " + sCriteria.ToString());
                  oAppointment = (Outlook.AppointmentItem)oItems.Find(sCriteria);
                  Console.WriteLine("Used Find with Date fields");
                  if (oAppointment is Outlook.AppointmentItem)
                        Console.WriteLine("Found -> " + oAppointment.Subject.ToString());
                        Console.WriteLine("No object found");

                  // Log off

                  // Clean up
                  oAppointment = null;
                  oRestrictedItems = null;
                  oItems = null;
                  oCalendar = null;
                  oNS = null;
                  oApp = null;

  • 5
  • 4
1 Solution
What IDE are you developing in?

If you are using Visual Studio or Visual C# Express Edition you can use a bunch of breakpoints to see where it is freezing.
Rowdyone52Author Commented:
It freezes here

Outlook.Application oApp = new Outlook.Application();

No clue why...
Does Outlook open up manually?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Rowdyone52Author Commented:
What do you mean manually?
Can you open up the program Outlook if you click on the Outlook icon?
Rowdyone52Author Commented:
oh yeah. definately.
I don't think you can spawn Outlook from ASP.Net.

That's too bad because that looks like that would be a nice app.

Maybe you could create a standalone app to run on the server to interact with Outlook and then your ASP.Net could interact with that app.
Rowdyone52Author Commented:
Thats a good idea, Im wondering what Exchange SDK would allow me to select the calendar events.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now