<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to drag, drop, and parse a CSV file in AIR</title>
	<atom:link href="http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/</link>
	<description>The Dead Tree Blog</description>
	<lastBuildDate>Wed, 18 Jan 2012 08:30:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Don Kerr</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-60162</link>
		<dc:creator>Don Kerr</dc:creator>
		<pubDate>Wed, 23 Nov 2011 02:01:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-60162</guid>
		<description>Hi Kalen,
For some reason, when I run this on my Mac it does not break it into individual lines 
var csvLines:Array = _content.split(String.fromCharCode(13,10));

The csv I&#039;m dropping was saved from MS Office Excel as csv.

Is there any specific save settings you need for the csv to recognize fromCharCode(13,10) ?

Your orders sample data works fine, but other csvs do not.  It like they are not outputting an end-of-line.

Any thoughts?

Thanks,
Don</description>
		<content:encoded><![CDATA[<p>Hi Kalen,<br />
For some reason, when I run this on my Mac it does not break it into individual lines<br />
var csvLines:Array = _content.split(String.fromCharCode(13,10));</p>
<p>The csv I&#8217;m dropping was saved from MS Office Excel as csv.</p>
<p>Is there any specific save settings you need for the csv to recognize fromCharCode(13,10) ?</p>
<p>Your orders sample data works fine, but other csvs do not.  It like they are not outputting an end-of-line.</p>
<p>Any thoughts?</p>
<p>Thanks,<br />
Don</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: guilherme</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-58874</link>
		<dc:creator>guilherme</dc:creator>
		<pubDate>Wed, 16 Nov 2011 16:55:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-58874</guid>
		<description>is that one day it will be possible in Flash in browsers like firefox and iexplorer? What I mean is do these events in the NativeDragManager in browsers that neither silverligth.</description>
		<content:encoded><![CDATA[<p>is that one day it will be possible in Flash in browsers like firefox and iexplorer? What I mean is do these events in the NativeDragManager in browsers that neither silverligth.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abhishek</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-26194</link>
		<dc:creator>abhishek</dc:creator>
		<pubDate>Tue, 31 May 2011 09:23:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-26194</guid>
		<description>with above example i&#039;m able to upload .csv file but not .xls file also how to use same code for uploaded file ?
:)</description>
		<content:encoded><![CDATA[<p>with above example i&#8217;m able to upload .csv file but not .xls file also how to use same code for uploaded file ?<br />
 <img src='http://www.kalengibbons.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos Ho</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-18331</link>
		<dc:creator>Carlos Ho</dc:creator>
		<pubDate>Wed, 09 Mar 2011 21:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-18331</guid>
		<description>Hi Kalen

I am trying to adapt your code to accept dragging an e-mail (and preferably with attachments) from a Thunderbird client.
I don´t know if I should consider an e-mail as a file or a text. Thunderbird seems to be a mix of both.
Should it be implemented as a custom clipboard format? What would be the strategy to solve this?

Hope not to confuse you by explaining what I am trying to do...

This would be a cool way to implement an e-mail forwarding or even files uploading to an air application.
I am saying AIR because I imagine that it must be a native approach to it.

Can you give me a hint?
Thank you very much indeed.

Carlos</description>
		<content:encoded><![CDATA[<p>Hi Kalen</p>
<p>I am trying to adapt your code to accept dragging an e-mail (and preferably with attachments) from a Thunderbird client.<br />
I don´t know if I should consider an e-mail as a file or a text. Thunderbird seems to be a mix of both.<br />
Should it be implemented as a custom clipboard format? What would be the strategy to solve this?</p>
<p>Hope not to confuse you by explaining what I am trying to do&#8230;</p>
<p>This would be a cool way to implement an e-mail forwarding or even files uploading to an air application.<br />
I am saying AIR because I imagine that it must be a native approach to it.</p>
<p>Can you give me a hint?<br />
Thank you very much indeed.</p>
<p>Carlos</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Garindeathray</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-4036</link>
		<dc:creator>Garindeathray</dc:creator>
		<pubDate>Wed, 21 Oct 2009 10:35:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-4036</guid>
		<description>RR-007 - I am very interested in your code to add sqlite but I can&#039;t seem to get it to work on my end. Would you be able to send me the source file?</description>
		<content:encoded><![CDATA[<p>RR-007 &#8211; I am very interested in your code to add sqlite but I can&#8217;t seem to get it to work on my end. Would you be able to send me the source file?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RR-007</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-842</link>
		<dc:creator>RR-007</dc:creator>
		<pubDate>Thu, 02 Apr 2009 22:55:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-842</guid>
		<description>I took a stab at completing this code to add info to a SQLite database. Everytime you drop the CSV file into the app, it will add the rows to the database and then display all rows. Below is the complete code.:

&lt;pre class=&quot;commentCode&quot;&gt;


	
		=0; i--){
			      statement.text = &quot;&quot;;
			      statement.text += &quot;INSERT INTO &quot; + tableName + &quot; &quot;;
			      statement.text += &quot;(orderID, date, type, description, amount) &quot;;
			      statement.text += &quot;VALUES(@orderID, @date, @type, @description, @amount)&quot;;
			      statement.parameters[&quot;@orderID&quot;] = categories[i].orderID;
			      statement.parameters[&quot;@date&quot;] = categories[i].date;
			      statement.parameters[&quot;@type&quot;] = categories[i].type;
			      statement.parameters[&quot;@description&quot;] = categories[i].description;
			      statement.parameters[&quot;@amount&quot;] = categories[i].amount;
			      statement.execute();
			   }
			   dbConnection.commit();
			}
			
			//GET RECORDS:
			//----------------------------------------------
			public function getData(_id:int=0):Array{
			   var statement:SQLStatement = new SQLStatement();
			   statement.sqlConnection = dbConnection;
			   statement.text = &quot;SELECT * FROM &quot; + tableName;
			   if(_id &gt; 0){
			      statement.text += &quot;WHERE transactionID = @id&quot;;
			      statement.parameters[&quot;@id&quot;] = _id;
			   }
			   statement.execute();
			   var result:SQLResult = statement.getResult();
			   return result.data;
			}

			
		
			private function onInit():void{
				//register event listeners
				this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, dragEnterHandler);
				this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, dragDropHandler);	
			}
			
			private function dragEnterHandler(evt:NativeDragEvent):void{
				/**
				 * if the file format is allowable, accept the file.
				 * you could easily limit this to only accept the file extension you want
				 * */
				if(evt.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)){
					NativeDragManager.acceptDragDrop(this);
				}
			}
			
			private function dragDropHandler(evt:NativeDragEvent):void{
				NativeDragManager.dropAction = NativeDragActions.COPY;
				myLabel.text = &quot;File Received&quot;;
				//get an array of the files dropped in
				var dropFiles:Array = evt.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
				//get the content of the file
				var fileContent:String = getFileContent(dropFiles[0]);
				//parse it to get an array of Orders
				var tempOrders:Array = new Array();
				tempOrders = parseCSV(fileContent);
				createDBConnection(&quot;orderDB&quot;,&quot;orders&quot;);
				save(tempOrders);
				orders = getData();
			}
			
			private function getFileContent(_file:File):String{
				//open a fileStream to read the content of the file
				var fileStream:FileStream = new FileStream();
				fileStream.open(_file, FileMode.READ);
				var fileContent:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
				fileStream.close();
				return fileContent;
			}
			
			private function parseCSV(_content:String):Array{
				//create temporary array to store the Orders
				var csvArray:Array = new Array();
				//break the csv into individual lines
				var csvLines:Array = _content.split(String.fromCharCode(13,10));
				//remove title row
				csvLines.splice(0,1);
				//loop over each line
				for each(var s:String in csvLines){
					var lineItems:Array = s.split(&quot;,&quot;);
					var transaction:Order = new Order(	lineItems[0],
														new Date(lineItems[1]),
														lineItems[2],
														lineItems[3],
														lineItems[4]);
					csvArray.push(transaction);
				}
				return csvArray;
			}
		]]&gt;
	
	
	
		
	
	
		
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I took a stab at completing this code to add info to a SQLite database. Everytime you drop the CSV file into the app, it will add the rows to the database and then display all rows. Below is the complete code.:</p>
<pre class="commentCode">

		=0; i--){
			      statement.text = "";
			      statement.text += "INSERT INTO " + tableName + " ";
			      statement.text += "(orderID, date, type, description, amount) ";
			      statement.text += "VALUES(@orderID, @date, @type, @description, @amount)";
			      statement.parameters["@orderID"] = categories[i].orderID;
			      statement.parameters["@date"] = categories[i].date;
			      statement.parameters["@type"] = categories[i].type;
			      statement.parameters["@description"] = categories[i].description;
			      statement.parameters["@amount"] = categories[i].amount;
			      statement.execute();
			   }
			   dbConnection.commit();
			}

			//GET RECORDS:
			//----------------------------------------------
			public function getData(_id:int=0):Array{
			   var statement:SQLStatement = new SQLStatement();
			   statement.sqlConnection = dbConnection;
			   statement.text = "SELECT * FROM " + tableName;
			   if(_id &gt; 0){
			      statement.text += "WHERE transactionID = @id";
			      statement.parameters["@id"] = _id;
			   }
			   statement.execute();
			   var result:SQLResult = statement.getResult();
			   return result.data;
			}

			private function onInit():void{
				//register event listeners
				this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, dragEnterHandler);
				this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, dragDropHandler);
			}

			private function dragEnterHandler(evt:NativeDragEvent):void{
				/**
				 * if the file format is allowable, accept the file.
				 * you could easily limit this to only accept the file extension you want
				 * */
				if(evt.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)){
					NativeDragManager.acceptDragDrop(this);
				}
			}

			private function dragDropHandler(evt:NativeDragEvent):void{
				NativeDragManager.dropAction = NativeDragActions.COPY;
				myLabel.text = "File Received";
				//get an array of the files dropped in
				var dropFiles:Array = evt.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
				//get the content of the file
				var fileContent:String = getFileContent(dropFiles[0]);
				//parse it to get an array of Orders
				var tempOrders:Array = new Array();
				tempOrders = parseCSV(fileContent);
				createDBConnection("orderDB","orders");
				save(tempOrders);
				orders = getData();
			}

			private function getFileContent(_file:File):String{
				//open a fileStream to read the content of the file
				var fileStream:FileStream = new FileStream();
				fileStream.open(_file, FileMode.READ);
				var fileContent:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
				fileStream.close();
				return fileContent;
			}

			private function parseCSV(_content:String):Array{
				//create temporary array to store the Orders
				var csvArray:Array = new Array();
				//break the csv into individual lines
				var csvLines:Array = _content.split(String.fromCharCode(13,10));
				//remove title row
				csvLines.splice(0,1);
				//loop over each line
				for each(var s:String in csvLines){
					var lineItems:Array = s.split(",");
					var transaction:Order = new Order(	lineItems[0],
														new Date(lineItems[1]),
														lineItems[2],
														lineItems[3],
														lineItems[4]);
					csvArray.push(transaction);
				}
				return csvArray;
			}
		]]&gt;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kalen Gibbons</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-20</link>
		<dc:creator>Kalen Gibbons</dc:creator>
		<pubDate>Tue, 03 Feb 2009 06:16:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-20</guid>
		<description>Hello Kastro,

Sorry for the late response, I&#039;m in the process of moving my blog to a new technology. I hope to write a full blog post about this soon, but for the meantime here are some basic examples of how to work with SQLite in AIR. I pulled these examples from separate pieces of code, so please keep in mind that these functions deal with different tables and won&#039;t necessarily work together. I hope this gets you started in the right direction.

&lt;pre class=&quot;commentCode&quot;&gt;
TO CREATE A DATABASE CONNECTION:
(this will create the db if it doesn&#039;t exist)
----------------------------------------------
public function createDBConnection(_dbName:String, _tableName:String){
   this.dbName = _dbName;
   this.tableName = _tableName;
   dbReference = File.applicationStorageDirectory.resolvePath(dbName+&quot;.db&quot;);
   dbConnection = new SQLConnection();
   dbConnection.open(dbReference);
}


TO CREATE A TABLE:
----------------------------------------------
public function createTable():void{
   var statement:SQLStatement = new SQLStatement();
   statement.sqlConnection = dbConnection;
   statement.text = &quot;CREATE TABLE IF NOT EXISTS &quot; + tableName + &quot; &quot;;
   statement.text += &quot;(ID INTEGER PRIMARY KEY AUTOINCREMENT, &quot;;
   statement.text += &quot;category TEXT, &quot;;
   statement.text += &quot;parentID INTEGER)&quot;;
   statement.execute();
}

INSERT RECORD:
----------------------------------------------
public function save(categories:Array):void{
   var statement:SQLStatement = new SQLStatement();
   statement.sqlConnection = dbConnection;
   // do this async, and in transaction/commit
   dbConnection.begin();
   for(var i:int=categories.length-1; i&gt;=0; i--){
      statement.text = &quot;&quot;;
      statement.text += &quot;INSERT INTO &quot; + tableName + &quot; &quot;;
      statement.text += &quot;(category, parentID) &quot;;
      statement.text += &quot;VALUES(@category, @parentID)&quot;;
      statement.parameters[&quot;@category&quot;] = categories[i].category;
      statement.parameters[&quot;@parentID&quot;] = categories[i].parentID;
      statement.execute();
   }
   dbConnection.commit();
}


GET RECORDS:
----------------------------------------------
public function getData(_id:int=0):Array{
   var statement:SQLStatement = new SQLStatement();
   statement.sqlConnection = dbConnection;
   statement.text = &quot;SELECT * FROM &quot; + tableName;
   if(_id &gt; 0){
      statement.text += &quot;WHERE transactionID = @id&quot;;
      statement.parameters[&quot;@id&quot;] = _id;
   }
   statement.execute();
   var result:SQLResult = statement.getResult();
   return result.data;
}
&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Hello Kastro,</p>
<p>Sorry for the late response, I&#8217;m in the process of moving my blog to a new technology. I hope to write a full blog post about this soon, but for the meantime here are some basic examples of how to work with SQLite in AIR. I pulled these examples from separate pieces of code, so please keep in mind that these functions deal with different tables and won&#8217;t necessarily work together. I hope this gets you started in the right direction.</p>
<pre class="commentCode">
TO CREATE A DATABASE CONNECTION:
(this will create the db if it doesn't exist)
----------------------------------------------
public function createDBConnection(_dbName:String, _tableName:String){
   this.dbName = _dbName;
   this.tableName = _tableName;
   dbReference = File.applicationStorageDirectory.resolvePath(dbName+".db");
   dbConnection = new SQLConnection();
   dbConnection.open(dbReference);
}

TO CREATE A TABLE:
----------------------------------------------
public function createTable():void{
   var statement:SQLStatement = new SQLStatement();
   statement.sqlConnection = dbConnection;
   statement.text = "CREATE TABLE IF NOT EXISTS " + tableName + " ";
   statement.text += "(ID INTEGER PRIMARY KEY AUTOINCREMENT, ";
   statement.text += "category TEXT, ";
   statement.text += "parentID INTEGER)";
   statement.execute();
}

INSERT RECORD:
----------------------------------------------
public function save(categories:Array):void{
   var statement:SQLStatement = new SQLStatement();
   statement.sqlConnection = dbConnection;
   // do this async, and in transaction/commit
   dbConnection.begin();
   for(var i:int=categories.length-1; i&gt;=0; i--){
      statement.text = "";
      statement.text += "INSERT INTO " + tableName + " ";
      statement.text += "(category, parentID) ";
      statement.text += "VALUES(@category, @parentID)";
      statement.parameters["@category"] = categories[i].category;
      statement.parameters["@parentID"] = categories[i].parentID;
      statement.execute();
   }
   dbConnection.commit();
}

GET RECORDS:
----------------------------------------------
public function getData(_id:int=0):Array{
   var statement:SQLStatement = new SQLStatement();
   statement.sqlConnection = dbConnection;
   statement.text = "SELECT * FROM " + tableName;
   if(_id &gt; 0){
      statement.text += "WHERE transactionID = @id";
      statement.parameters["@id"] = _id;
   }
   statement.execute();
   var result:SQLResult = statement.getResult();
   return result.data;
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kastro</title>
		<link>http://www.kalengibbons.com/blog/index.php/2008/11/how-to-drag-drop-and-parse-a-csv-file-in-air/comment-page-1/#comment-19</link>
		<dc:creator>Kastro</dc:creator>
		<pubDate>Wed, 30 Jan 2008 15:28:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=61#comment-19</guid>
		<description>Thanks Kalen for this example. I am curious however how to import this data into the SQLlite db. Would you happen to have a quick explanation?

Thanks :)</description>
		<content:encoded><![CDATA[<p>Thanks Kalen for this example. I am curious however how to import this data into the SQLlite db. Would you happen to have a quick explanation?</p>
<p>Thanks <img src='http://www.kalengibbons.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

