Adobe Air , export data to .ics and import to google Calendar

Let’s assume you have a dataGrid with some data, and they are categorized by date. Then you wanted to import those data/notes to google calendar (create one and name it “sample Calendar”, or change the calendar name below to match one of your already created calendars.


/* This functionality is implemented in my Calendar Application, and the source code including these functions will be available in the following days at: Google Code

Here is how:

first of you will need the place to save the file…

public function saveAs():void


var docsDir:File = File.documentsDirectory;

var typeArr:Array=[“.ics”,”.txt”];



docsDir.browseForSave(“Save As: || Type only name without extension”);

docsDir.addEventListener(Event.SELECT, saveICS);


catch (error:Error){

trace(“Failed:”, error.message);



//then you will need the google Calendar .ics structure

public function saveICS(event:Event)


var newFile:File = as File;

newFile.nativePath +=”.ics”;

var arr:Array=[];

var FINAL_STR:String =””;

/*initialization options, no need to recreate. use as is. */



“PRODID:=//Google Inc//Google Calendar 70.9054//EN”+”\n”+




“X-WR-CALNAME:sample Calendar”+”\n”+



//to go through the whole dataGrid

for (var i=1;i {

arr[i] = [







“DESCRIPTION: “+String(stripHtmlTags(dg.dataProvider[i-1].comments).replace(/”/g,” “))+”\n”+


“LOCATION: – “+”\n”+







FINAL_STR += arr[i];
arr[dg.dataProvider.length] =

// Save the file

var stream:FileStream = new FileStream();, FileMode.WRITE);

/* some formation functions. depends on the format you use on the dataGrid, you might or might not need them. */

public function formatTime(pos,str:String):String
var timeArr:Array=[];
var hh = “”;
var mm = “”;
var ss = “00”;

timeArr = str.split(“–“);
if (pos == “s”)
hh = String(timeArr[0]).slice(0,2);
mm = String(timeArr[0]).slice(-2);

FINAL_TIME = hh+mm+ss;
else if(pos == “e”)
hh = String(timeArr[1]).slice(0,2);
mm = String(timeArr[1]).slice(-2);

FINAL_TIME = hh+mm+ss;

public function formatMonth(str)

if (Number(str)<10) str = "0">

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *