Asp.Net - Code Hangs...

Posted on 2006-04-11
Last Modified: 2010-04-16
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;

Question by:Rowdyone52
    LVL 14

    Expert Comment

    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.

    Author Comment

    It freezes here

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

    No clue why...
    LVL 14

    Expert Comment

    Does Outlook open up manually?

    Author Comment

    What do you mean manually?
    LVL 14

    Expert Comment

    Can you open up the program Outlook if you click on the Outlook icon?

    Author Comment

    oh yeah. definately.
    LVL 14

    Accepted Solution

    I don't think you can spawn Outlook from ASP.Net.
    LVL 14

    Expert Comment

    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.

    Author Comment

    Thats a good idea, Im wondering what Exchange SDK would allow me to select the calendar events.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now