Git Product home page Git Product logo

azure-functions-create-ics-file-using-csharp-sample's Introduction

page_type languages products description urlFragment
sample
csharp
azure
This is a sample HTTP trigger Azure Function that returns a ICS file that to the client.
ics-file-generator

C# Azure Function for generating an ICS File

This is a sample HTTP trigger Azure Function that returns a ICS file that to the client. The project takes a dependency on iCal.NET, but demonstrates how a simple HTTP Trigger can be implemented.

Additional Details and History

This project originally came out a need to create an ICS file for the Azure Functions webinar. Armed with only the knowledge of what I wanted to create, below is how I started investigating how to do this with Azure Functions :

I began by taking a look at a third party library called iCal.NET. It looks like this handles all the various time zones and client. Next, I opened the Azure Portal and creating a new Azure Function application securing the name that folks would go to :

image

Next, I chose a language and happily picked C# and used a HttpTrigger template.

image

By default, the code in the template is looking for a name parameter and a POST command. Since, I didn't want to respond to a POST, but rather just a GET, I used this as my start but deleted the name parameter section.

Armed with just the online editor, I started writing code. I could have downloaded Visual Studio 2017 Preview 3 and the Azure Function tooling for a richer debugging experience, but it was getting late and I wanted to crank this out with just a browser and my C# skills.

I needed to pull in a third party library, so I noticed that you could view "Files" inside the portal and that it supports NuGet. I simply created a project.json and added the following NuGet package reference to iCal.NET and Newtonsoft.Json :

{
  "frameworks": {
    "net46": {
      "dependencies": {
	"Ical.Net": "2.2.19",
	"Newtonsoft.Json": "9.0.1"
      }
    }
   }
}

When I switched back to my function, I noticed my project started pulling down the references and restarted my function.

The code is pretty self-explanatory if you've used iCal.NET before, but basically I create the file and ensure when someone visits the site that it sends down an ICS file named webinarinvite.ics.

During the process of working with the function, I hit the "Save" button and it would let me know if it compiled successfully or not. It finally compiled successfully as shown below :

2017-06-06T23:19:02  Welcome, you are now connected to log-streaming service.
2017-06-06T23:20:02  No new trace in the past 1 min(s).
2017-06-06T23:23:04.794 Function started (Id=xxx-1d71-4f1f-8fbd-6d1b4dcc96f0)
2017-06-06T23:23:05.921 Function completed (Success, Id=xxx-1d71-4f1f-8fbd-6d1b4dcc96f0, Duration=1137ms)

Very cool! Now to test the function, it was as simple as selecting GET from the dropbox on the Test Tab and hitting the Run button.

image

Now that my function was working properly, I grabbed the URL to my app and pasted it into the browser. The URL was easy to find as shown below:

image

Success! It downloaded the .ICS file and after opening it, the following entry appeared in my calendar :

image

I've recently checked the traffic using the "Monitor" section and noticed it has already received 393 downloads!

image

Whenever I need to update this in the future, all it will require is changing two lines. No additional servers, redeployment, etc. is needed as it will auto compile.

Btw, you can try it now at http://aka.ms/AzureFunctionsLive and be sure to follow @AzureFunctions on Twitter!

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

azure-functions-create-ics-file-using-csharp-sample's People

Contributors

mbcrump avatar microsoftopensource avatar msftgits avatar supernova-eng avatar v-hearya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.