I normally code in PHP and Python, but in this case i have to make it in C#.
I have this code, It works really good. It is a console application.
But how can you make it to a C# .net so that is can put it on a IIS?
Basicly instead of outputting it to a console, it should just write it to the browser.
I have tried to search for C# Web, but could not find anything.
Thanks for the help!
using System;
using System.Net;
using Independentsoft.Exchange;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
NetworkCredential credential = new NetworkCredential("username", "password");
Service service = new Service("https://myserver/ews/Exchange.asmx", credential);
try
{
IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(AppointmentPropertyPath.StartTime, DateTime.Today);
IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime, DateTime.Today.AddDays(1));
And restriction3 = new And(restriction1, restriction2);
FindItemResponse response = service.FindItem(StandardFolder.Calendar, AppointmentPropertyPath.AllPropertyPaths, restriction3);
for (int i = 0; i < response.Items.Count; i++)
{
if (response.Items[i] is Appointment)
{
Appointment appointment = (Appointment)response.Items[i];
Console.WriteLine("Subject = " + appointment.Subject);
Console.WriteLine("StartTime = " + appointment.StartTime);
Console.WriteLine("EndTime = " + appointment.EndTime);
Console.WriteLine("Body Preview = " + appointment.BodyPlainText);
Console.WriteLine("----------------------------------------------------------------");
}
}
Console.Read();
}
catch (ServiceRequestException ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.WriteLine("Error: " + ex.XmlMessage);
Console.Read();
}
catch (WebException ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.Read();
}
}
}
}
EDIT: I have tried to make it a asp.net page
But it do not print anything to the screen.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Plan.NBT.Final.Default" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="Independentsoft.Exchange" %>
<%
NetworkCredential credential = new NetworkCredential("tedy", "123456889");
Service service = new Service("https://area51.com/EWS/exchange.asmx", credential);
try
{
IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(AppointmentPropertyPath.StartTime, DateTime.Today);
IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime, DateTime.Today.AddDays(1));
And restriction3 = new And(restriction1, restriction2);
FindItemResponse response = service.FindItem(StandardFolder.Calendar, AppointmentPropertyPath.AllPropertyPaths, restriction3);
for (int i = 0; i < response.Items.Count; i++)
{
if (response.Items[i] is Appointment)
{
Appointment appointment = (Appointment)response.Items[i];
Response.Write("Subject = " + appointment.Subject);
Response.Write("StartTime = " + appointment.StartTime);
Response.Write("EndTime = " + appointment.EndTime);
Response.Write("Body Preview = " + appointment.BodyPlainText);
Response.Write("----------------------------------------------------------------");
}
}
}
%>
ok a quick and dirty asp.net webpage sample. Basically your Main becomes PageLoad. Be sure that your code behind pages inherit System.Web.UI.Page (if you are using VS2008 or VS2010 then it is taken care of for you.
}
then your viewpage could be like this. Be sure that the CodeBehind is pointing to the class with the code to do all the heavy lifting for the page.
obviously there is a lot more you can/should do with master pages, styling and a bunch of other stuff. This is just a basic vanilla codebehind and page.