Microsoft.Graph.Models.RecurrencePattern to RRule Converter

Jiya desai 51 Reputation points
2023-11-22T17:18:32.4066667+00:00

Hi,

I am reading Microsoft Calendar using Microsoft Graph SDK Library and want to save the content into .ics and .csv format. for which i need to convert propriety Microsoft.Graph.Models.RecurrencePattern to standard RRule format.

Can anyone throw some light? Any sample code or Is there any Converter library available ?

Regards

Outlook
Outlook
A family of Microsoft email and calendar products.
3,406 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,393 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,066 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 40,221 Reputation points
    2023-11-23T07:02:25.7666667+00:00

    Hi @Jiya desai

    What you need to do is:

    • Create a StringBuilder object to store the event data.
    • Write a header line containing the event properties you want to return, such as ID, subject, start time, end time, etc. Separate each property with a comma.
    • Iterate through the result object, which is an IEventCollectionPage object that contains a list of Event objects. For each Event object, write its properties to the StringBuilder object and separate them with commas. After writing each Event object, start a new line.
    • Use the File.WriteAllText() method to save the contents of the StringBuilder object as a .csv file. Refer to the following code example:
    var result = await graphClient.Users["{user_id}"].Calendar.Events.GetAsync();
    
    // Create a string builder to store the event data
    var sb = new StringBuilder();
    
    // Write the header row
    sb.AppendLine("id,subject,start,end,location,attendees");
    
    // Write the event data
    foreach (var e in result.Value)
    {
        sb.Append(e.Id + ",");
        sb.Append(e.Subject + ",");
        sb.Append(e.Start.DateTime + ",");
        sb.Append(e.End.DateTime + ",");
        sb.Append(e.Location.DisplayName + ",");
        sb.Append(string.Join(";", e.Attendees.Select( a => a.EmailAddress.Address)));
        sb.AppendLine();
    }
    
    // Save the string builder content as a .csv file 
    File.WriteAllText("C:\\events.csv", sb.ToString());
    

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.