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());
                        Console.WriteLine("\n\n");
                        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());
                  else
                        Console.WriteLine("No object found");


                  // Log off
                  oNS.Logoff();

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



            }
Rowdyone52Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CtrlAltDlCommented:
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...
CtrlAltDlCommented:
Does Outlook open up manually?
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

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

http://support.microsoft.com/kb/q237913/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CtrlAltDlCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.