How to extract data using Ical.Net? - c#

I have an ics file I want to read data out from. I downloaded Ical.Net using Nuget and I'm trying to figure out how to work with it. All I want to do is get the same info as I would get if I uploaded my ics file to this website: https://icsconvert.appspot.com/
Which is, for each "event":
Summary
Description
Start
End
Location
But I don't understand how I can get that info out of the file. Here's what I have so far:
string filepath = #"C:\My\file\path\myIcs.ics";
System.IO.StreamReader file = new System.IO.StreamReader(filepath);
string content = file.ReadToEnd();
file.Close();
Ical.Net.Calendar calendar = Ical.Net.Calendar.Load(content);
foreach (var c in calendar.RecurringItems)
{
// 1. Do something!
// 2. ????
// 3. Profit!
}
Here's a sample file I got from here:
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Access-A-Ride Pickup
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
LOCATION:1000 Broadway Ave.\, Brooklyn
DESCRIPTION: Access-A-Ride trip to 900 Jay St.\, Brooklyn
STATUS:CONFIRMED
SEQUENCE:3
BEGIN:VALARM
TRIGGER:-PT10M
DESCRIPTION:Pickup Reminder
ACTION:DISPLAY
END:VALARM
END:VEVENT
BEGIN:VEVENT
SUMMARY:Access-A-Ride Pickup
DTSTART;TZID=America/New_York:20130802T200000
DTEND;TZID=America/New_York:20130802T203000
LOCATION:900 Jay St.\, Brooklyn
DESCRIPTION: Access-A-Ride trip to 1000 Broadway Ave.\, Brooklyn
STATUS:CONFIRMED
SEQUENCE:3
BEGIN:VALARM
TRIGGER:-PT10M
DESCRIPTION:Pickup Reminder
ACTION:DISPLAY
END:VALARM
END:VEVENT
END:VCALENDAR
How can I get the data I want? I want to use the foreach to save that data into a custom list.

As far as I can see you just have a set of two separate events there, not recurring events (as in defined with an RRULE).
I think you would likely find what you need in calendar.Events instead (I've never used this library, just had a quick poke at the source code and it looks like the calendar class has an "Events" property).

Related

Read Undelivered email body in C# windows form

I am developing one tool to keep track of emails and would like to trace the emails undelivered to sender.
I dont want to use any third party tool or any external reference
What I have tried?
-To read report Item but Body is in Chinese like language
-Googled on some solutions but nothing is working i.e. solution is related to
//PR_TRANSPORT_MESSAGE_HEADERS
link to get property name "http://schemas.microsoft.com/mapi/proptag/0x0C1A001F"
outlook PropertyAccessor class
PropName link is not working anymore.
Could anyone here please help me I would like to get from which sender the email delivery is failed.
Thank you in advance.
The PR_TRANSPORT_MESSAGE_HEADERS property contains the same Diagnostic information shown in the body. You just need to read it using the PropertyAccessor class and parse the string with From and To entries.
Outlook.PropertyAccessor oPA = reportItem.PropertyAccessor;
string transportHeaders = (string)oPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");

EWS C# property LastModifiedTime time not updated after read or unread message

I am doing search for mails using a specific date. I use an or filter with the parameters DateTimeCreated, DateTimeReceived and lastModifiedTime. I also search for a specific property.
The search query is working for messages received or modified (i.e. moved to other folder) after the specific date.
I noticed that messages created before the specific date and changed to read or unread after the specific date are not being retrieved. I expected that messages changed to read or unread had the lastModifiedTime property changed. Below the
code I am using:
List<SearchFilter> SearchFilterOrColletion = new List<SearchFilter>();
SearchFilterOrColletion.Add(new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeCreated, UTCfromDate));
SearchFilterOrColletion.Add(new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, UTCfromDate));
SearchFilterOrColletion.Add(new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.LastModifiedTime, UTCfromDate));
SearchFilter SearchOrFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, SearchFilterOrColletion.ToArray());
List<SearchFilter> SearchAndFilter = new List<SearchFilter>();
SearchAndFilter.Add(SearchOrFilter);
SearchAndFilter.Add(SearchFilterXprProperty);
SearchFilter.SearchFilterCollection FinalSearchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, SearchAndFilter.ToArray());
Is there a way to get the time the message was set to read or unread ?
i.e:
1 - Message A received 3:30 pm
2 - Message B received 4:00 pm
3 - Message A read 4:10 pm
Using my search with the time 3:50pm is returning only the message B. I was expecting the message A would be found too (due to the lastModifiedTime) property.
Thank you in advance,
Its not a bug updating the Read status of a Message doesn't change Last Modified time (this has always been the case in exchange), the one exception is when you reply or forward a message this will modify the PR_LAST_VERB_EXECUTED property which will then update the Last Modified time.
If you want to track when a Message is read you need to use http://blogs.technet.com/b/exchange/archive/2010/01/13/exchange-2010-delivery-reports.aspx or you can use EWS Notification and subscribe to the OnRead notification
Cheers
Glen

Google calendar incorrect imports DDay multiple-day events

I'm using a DDay library to create iCal file. Here's an example of one event that I created:
BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
PRODID:-//MyProduct
BEGIN:VEVENT
CATEGORIES:Office event
DESCRIPTION:Rudniy\, Kazahstan office has a work day.
DTEND;VALUE=DATE:20141207
DTSTAMP:20141230T085900Z
DTSTART;VALUE=DATE:20141206
SEQUENCE:0
SUMMARY:Work Day in RDN
UID:6418abbe-1904-40c4-8544-e87dd4f4c002
END:VEVENT
END:VCALENDAR
When I import that calendar to Google Calendar, the result event is only on 2014-12-06 and is one day long (instead of two).
Can please somebody tell what's wrong?
When you use end.date and start date properties, you will give date in the format "yyyy-mm-dd". In google calendar, these properties are used to create ONLY "All-day events". Here is link for the details on using properties.
Try using the properties end.dateTime(format is 2015-01-03T10:00:00.000-07:00) and start.dateTime properties to create multiple-day events.
Okay, finally I got it. The END date specifies NON-INCLUSIVE end date for event. So I just should add 1 day to each end date by myself.

Outlook 2010 shows time one hour ahead

I have created following ".ics" file. When I open it in Google and iCal it shows correct time but when I open in Outlook 2010 it shows time one hour ahead. Any help?
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//www.marudot.com//iCal Event Maker
X-WR-TIMEZONE:America/Los_Angeles
BEGIN:VEVENT
DTSTART;TZID=America/Los_Angeles:20140510T110000
DTEND;TZID=America/Los_Angeles:20140510T111500
SUMMARY:Appointment-11:00 AM-PST
DESCRIPTION:Appointment-11:00 AM-PST
LOCATION:Location: TBD
END:VEVENT
END:VCALENDAR
When using local time with timezone, adding a TZID to all date related properties is not enough. That is because there is no global registry of TZID that is understood by all clients. Hence, one must include in the iCalendar stream the timezone definition that corresponds to this TIZD.
In other words, your stream is not iCalendar compliant. Before the event (before BEGIN:VEVENT), you should have a proper VTIMEZONE definition corresponding to the TZID America/Los_Angeles. See https://www.rfc-editor.org/rfc/rfc5545#section-3.8.3.1
In your case, it would be something like:
BEGIN:VTIMEZONE
TZID:America/Los_Angeles
TZURL:http://tzurl.org/zoneinfo/America/Los_Angeles
X-LIC-LOCATION:America/Los_Angeles
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
TZNAME:PDT
DTSTART:20070311T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
TZNAME:PST
DTSTART:20071104T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE
I don't think "TZID=America/Los_Angeles" is a time zone that Outlook understand. Try to create a an appointment in Outlook and save it as an ICS file. What TZ does Outlook use?

The internet calendar file "abc.ics" does not contain any appointments

I have created a .ics VTODO calender, but when I open the file in Microsoft outlook its shows the following error
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//DDay.iCal//NONSGMLddaysoftware.com//EN
BEGIN:VTODO
CREATED:20070101T000000Z
DESCRIPTION:fdsdsfds
DTSTAMP:20070101T000000Z
DTSTART:20070101T080000
DUE;VALUE=DATE:20070107
DURATION:P5DT16H
SEQUENCE:0
STATUS:NEEDS-ACTION
SUMMARY:xxxx
UID:b6709c95-5523-46aa-a7e5-1b5ea034b86a
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Reminder
TRIGGER:-PT30M
END:VALARM
END:VTODO
END:VCALENDAR
VTODO is not supported by Outlook: see Microsoft's spec (https://msdn.microsoft.com/en-gb/library/cc463911.aspx)

Categories

Resources