通常は PHP と Python でコーディングしますが、この場合は C# で作成する必要があります。
私はこのコードを持っています、それは本当にうまくいきます。コンソールアプリケーションです。
しかし、IIS に配置できるように、C# .net にするにはどうすればよいでしょうか。
基本的に、コンソールに出力する代わりに、ブラウザに書き込むだけです。
C# Web を検索しようとしましたが、何も見つかりませんでした。
助けてくれてありがとう!
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();
}
}
}
}
編集:私はそれをasp.netページにしようとしましたが、画面には何も出力されません。
<%@ 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("----------------------------------------------------------------");
}
}
}
%>