I have a program which fetches appointments from Microsoft Exchange for a given calendar and I want to output these in an ASP.net file
The "code behind" I have is:
DateTime StartDate = DateTime.Today;
DateTime EndDate = DateTime.Today.AddDays(1);
CalendarView cv = new CalendarView(StartDate, EndDate);
String MailboxToAccess = "RES_03037#company.com";
FolderId CalendarFolderId = new FolderId(WellKnownFolderName.Calendar, MailboxToAccess);
FindItemsResults<Appointment> fapts = service.FindAppointments(CalendarFolderId, cv);
if (fapts.Items.Count > 0)
{
DataRow row = table2.NewRow();
foreach (Appointment Appoint in fapts)
{
//Output to ASPX file
}
}
I am fairly new to ASP and C#
Your advice will be much appreciated!
Related
I'm trying to fetch detail of the email address from Attendees because of more addresses in the group, this is my code.
public List<Meeting> getAll(string email, string sDate, string eDate)
{
List<Meeting> res = new List<Meeting>();
ExchangeService es = new ExchangeService();
string username = Properties.Settings.Default.username;
string password = Properties.Settings.Default.password;
SecureString ssPassword = new SecureString();
foreach (char x in password)
ssPassword.AppendChar(x);
es.Credentials = new NetworkCredential(username, ssPassword);
es.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
FolderId folderID = new FolderId(WellKnownFolderName.Calendar, "xxxxxx#xxxx.com");
DateTime startDate = DateTime.ParseExact(sDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
DateTime endDate = DateTime.ParseExact(eDate + " 23:59:59", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
CalendarView cView = new CalendarView(startDate, endDate);
//cView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
FindItemsResults<Item> resultItem = es.FindItems(folderID, cView);
foreach (Item item in resultItem.Items)
{
ServiceResponseCollection<GetItemResponse> itemResponseCollection = es.BindToItems(new[] { new ItemId(item.Id.UniqueId) }, new PropertySet(BasePropertySet.FirstClassProperties));
foreach (GetItemResponse itemResponse in itemResponseCollection)
{
Appointment app = (Appointment)itemResponse.Item;
res.Add(GetClassFromAppointment(app));
}
}
return res;
}
obj.Attendees = {aaa#xxxx.com, bbb#xxxx.com, Group#xxxx.com}
"Group#xxxx.com" include more emaill address: ccc#xxxx.com, ddd#xxxx.com
How to fetch detail's addresses from the group?
You should be about just to use the EWS ExpandGroup operation https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-expand-distribution-groups-by-using-ews-in-exchange-2013. eg with your code something like
// Return the expanded group.
ExpandGroupResults myGroupMembers = es.ExpandGroup("Group#xxxx.com");
// Display the group members.
foreach (EmailAddress address in myGroupMembers.Members)
{
Console.WriteLine("Email Address: {0}", address);
}
Another approach is because you using Office365 is that you can get the Group members using the Microsoft Graph API https://learn.microsoft.com/en-us/graph/api/group-list-members?view=graph-rest-1.0&tabs=http
I am new to CRM 2015 and I want to write C# method which connects to CRM and return only holiday date list from calendar like this:
List<DateTime> lst = GetHolidayListFromCRM();
......
public List<DateTime> GetHolidayListFromCRM()
{
IOrganizationService service = GetServiceProxy(USERNAME, PASSWORD, DOMAIN, CRM_URL);
using (OrganizationServiceContext svcContext = new OrganizationServiceContext(service))
{
var info = svcContext.CreateQuery("calendar");
//Some code here for processing and returning only holiday date list
}
}
List<DateTime> ret = new List<DateTime>();
QueryExpression qe = new QueryExpression("calendar");
qe.Criteria.AddCondition("name", ConditionOperator.Equal, "Business Closure Calendar");
EntityCollection ec = service.RetrieveMultiple(qe);
if (ec.Entities.Count != 1) { return ret; }
Entity calendar = ec.Entities[0];
if(!calendar.Contains("calendarrules")) { return ret; }
EntityCollection rules = calendar.GetAttributeValue<EntityCollection>("calendarrules");
foreach (Entity rule in rules.Entities)
{
ret.Add(rule.GetAttributeValue<DateTime>("startime"));
// Console.Out.WriteLine("{0}:{1}", rule["starttime"], rule["name"]);
}
return ret;
Note: It is not possible to access directly calendar rule:
http://www.inogic.com/blog/2014/08/calendars-and-expand-calendar-request-in-crm-2013-sp-1/
https://community.dynamics.com/crm/f/117/t/185090
https://msdn.microsoft.com/en-us/library/gg327912.aspx?f=255&MSPPError=-2147217396
I'm currently trying to retrieve public Appointments of a users Calendar in Outlook (with Exchange2013) to a DataSet to be displayed later on.
Here's the relevant code so far:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.AutodiscoverUrl("mail#mycompany.com", RedirectionCallback);
DateTime reportDate = dateTimePicker1.Value;
DateTime startDate = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day, 0, 0, 1);
DateTime endDate = startDate.AddHours(23);
endDate = endDate.AddMinutes(59);
CalendarFolder calendar = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, "somemail#mycompany.com"));
CalendarView cView = new CalendarView(startDate, endDate);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Location);
// get appointment collection
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
// transfer to DataSet
DataSet1.Tables[0].Rows.Clear();
int i = 0;
foreach (Appointment a in appointments) {
DataSet1.Tables[0].Rows.Add(
i++.ToString(),
a.Subject.ToString(),
a.Start.ToString(),
a.End.ToString(),
a.Location.ToString());
}
An exception is being shown in the Line
CalendarFolder calendar = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, "somemail#mycompany.com"));
Any ideas what I'm doing wrong here? Or is there even a completely other way on how to approach my problem?
The account which you are using to connect tho the exchange server doesn't have permission to read the mailbox of somemail#mycompany.com. Try to get a super user privilege for the account. Hope this is useful.
I want to list all Outlook appointment times in a specific time range and I am only interested in start and end time of the appointments.
I'm using this code so far:
DateTime startTime = DateTime.Now.AddDays(2);
DateTime endTime = DateTime.Now.AddDays(3);
var outlookApplication = new Outlook.Application();
Outlook.NameSpace outlookNamespace = outlookApplication.GetNamespace("MAPI");
var recip = outlookNamespace.CreateRecipient("<valid contact>");
if (recip.Resolve())
{
var calendarItems = outlookNamespace.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderCalendar).Items;
calendarItems.IncludeRecurrences = true;
var filter = String.Format("[Start] >= '{0}' And [End] < '{1}'", startTime.ToShortDateString(), endTime.ToShortDateString());
calendarItems.Sort("[Start]");
calendarItems = calendarItems.Restrict(filter);
var result = calendarItems.Cast<AppointmentItem>().Select(x => x);
}
The code retrieves nearly all appointments, but not the private ones. How can I get the private appointments too?
Outlook always filters out private appointments form the shared folders even if they are perfectly accessible using MAPI. If using Redemption (I am its author) is an option, you can use RDOFolder.GetActivitiesForTimeRange - it returns private appointments.
I'm creating reports in C# ASP.Net, whereby in the reports I can filter data created between two different dates (e.g Start date: 15th July and End date: 17th July) but when it comes to filtering data created on a particular day (e.g StartDate: 15th July and End Date: 15th July) the query doesn't retrieve anything...
//Code from OutletDistributor.aspx.cs
ReportManager master = ObjectFactory.GetInstance<ReportManager>();
ReportResponse responce = new ReportResponse();
if (ddDistributor == Guid.Empty)
responce = master.GetAllOutletDistributor(sDate, EDate);
else
responce = master.GetOutletDistributor(sDate, EDate, ddDistributor);
ReportViewer1.Reset();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
var stream = Assembly.GetAssembly(typeof(SampleReport)).GetManifestResourceStream(responce.ReportResource);
ReportDataSource reportDataSource = new ReportDataSource(responce.ReportDataSet, responce.ReportDataSource);
stream = RdlcReportHelper.TranslateReport(stream);
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
ReportViewer1.LocalReport.LoadReportDefinition(stream);
ReportViewer1.LocalReport.DisplayName = ResourceHelper.GetText(null, "hq.rpt.outletdist.heading");
ReportViewer1.LocalReport.Refresh();
//Code from ReportManager.cs
//Filter All Outlet Distributor
public ReportResponse GetAllOutletDistributor(DateTime StartDate, DateTime EndDate) {
ReportResponse report = new ReportResponse();
report.ReportResource = "Distributr.HQ.Lib.Reports.RcdlFiles.OutletDistributor.rdlc";
List<OutletReportItem> Report = _outletReport.GetAllOutlets()
.Where(p => p.CreationDate >= StartDate && p.CreationDate <= EndDate).ToList();
Report.ForEach(n => report.ReportDataSource.Add(n));
report.ReportDataSet = "dsOutletDistributor";
return report;
}
I assume that StartDate and EndDate both contain a time component. Remove it using the Date property:
StartDate = StartDate.Date;
EndDate = EndDate.Date;
// your query goes here...
Actually, your code List<OutletReportItem> Report = _outletReport.GetAllOutlets().Where(p => p.CreationDate >= StartDate && p.CreationDate <= EndDate).ToList() when initialize the object DateTime so the default value of date with hours, minutes and seconds which are '00'. So I think you could use DateTime.Compare()
In this condition where your date is same use "=" (instead of difference) in your query