Copy DB file From Flex AIR bindebug Folder To Any Folder Programatically - apache-flex

I have a db file Resided in Flex Air Bindebug Folder,Here i want to Move/save this db File at another location let say In mydocument/or any Folder, I am not able to do it's programatically..Please help me out here.
Thanks in advance.

Assuming mydbfile.db is the file in your Application Directory:
var fileToCopyFrom:File = File.applicationDirectory.resolvePath("mydbfile.db");
var fileToCopyTo:File = File.documentsDirectory("Copy of mydbfile.db");
fileToCopyFrom.copyTo(fileToCopyTo as FileReference);
This would copy the file to your Documents directory. These are all basic functions weill documented in the AS3 Reference for flash.filesystem.File.

Are your trying to do this via actionscript or in FlashBuilder/Eclipse?
If your trying to move around in The IDE then use ANT.

Related

Setting custom local storage Path in QML

I m trying to put a custom path in QML file but can't get it done.
I'm trying to get de db in a shared folder where i'm willing to put the DB so any person who has the program can acces to data.
I'm using Sqlite and Qt Creator 5.7 but not a lot of info about this.
You can simply COPY the database from its default path. Typically that is located (In windows anyways) at
C:\Users\<username>AppData\Local\<program name>\QML\OfflineStorage\Databases
and on Mobile devices it is stored in a similar place --
on android its in a sub folder of:
/data/data/<Program Name>
On *nix it is located:
/home/<user>/.local/share/[ProjectName]/QML/OfflineStorage/Databases

flashbuilder 4.6 - How do I include a sqlite db and copying to storageDirectory

Im completing an app in flashbuilder 4.6 and originally was creating a new sqlite database and table within it, on the fly, when the app was first run... but I now want to include a database file in the /src/views/assets/ folder and when the app is run, copy that file to the application.StorageDirectory -- I cant find any examples of how to pull this off. can anyone shed any light on how the process / actionscript for it would look?
You can use File.copyTo:
var sourceFile:File = File.applicationDirectory.resolvePath("/views/assets/database.file");
var destination:File = File.applicationStorageDirectory.resolvePath("database.file");
sourceFile.copyTo(destination, true);
Where database.file is your sqlite file. You may need to tweak the path for sourceFile to match where your assets are.
Second parameter of copyTo specifies whether to overwrite any existing file.

Can not write to sqlite db in packaged air

I can write to db when running in IDE(FB), while after packaging a air, the app wont write to sqlite db, Why? Thanks in advance.
The likely cause is that your installed Air application can't resolve the path to your sqlite file.
What I normally do is to use one of the static public properties of the File class to resolve my sqlite file from eg.
databaseConnection = new SQLConnection();
databaseConnection.addEventListener(SQLEvent.OPEN, onOpen);
databaseConnection.addEventListener(SQLErrorEvent.ERROR, onError);
databaseConnection.openAsync(File.applicationDirectory.resolvePath('mydb.sqlite'));
The key bit here is the File.applicationDirectory.resolvePath('mydb.sqlite') line, in this instance AIR will look for a file called mydb.sqlite in the directory that the application is installed into - in your development environment this would be the same as the bin-debug folder (or whatever folder you are compiling to).
Hope that helps, if not if you can post the code you are using , and what error you are getting I will try and help you further.
The most likely reason is that your DB file resides in the application directory, which is read only.
From Flex 3.5 Language Reference:
File.applicationDirectory—the read-only directory where the application is installed (along with any installed assets)
If this is the case, a possible but not only easy fix would be to just use File.applicationStorageDirectory.
Hope this helps.
N.

how to find local image in asp.net project?

I have a solution contains a web project named "Web", and a dependeny class library project named "Service". I use the ASP.Net MVC2 to build up my solution. As you know, there's a Content folder storing images and css files under the web project. Now I need to get the stream reference of "Content\Images\anon.png" in one class of my "Service" project.
I tried
var result = new FileStream(#"Content\Images\anon.png", FileMode.Open);
and press F5 to debug, but it cannot find the file and throws an exception.
I am using VS2010, please tell me how can I access to this image. Thanks very much.
Can you try
Server.MapPath("~/Content/Images/anon.png")
You can use System.Web.VirtualPathUtility.ToAbsolute("~/Content/Images/anon.png"); or RequestContext.HttpContext.Request.MapPath as well
Visual studio makes it to a temp directory for your web app, not your solution folder/ If you publish your app on a IIS server, the Server.map will be correct.
Because it is searching for the file in Debug\Content\Images\ . Are you sure the images is really there? Make sure that your file is in that path.

Check Folder as Write access,Air app ,Flex

how to know the folder as write permission in air application..in my application i am saving txt file in folder,so that i need to test that folder as write permission...
var file:File = File.desktopDirectory.resolvePath("TxtFolder/DataFile.txt");
i need to check "TxtFolder" has write permission...? before saving the file(DataFile.txt)..how can i do it in flex Air as3
Thanks In Advance...
You can handle ioError event which FileReference dispatches when you don't have permissions to write into directory.
Run the AIR app as administrator and you can even write inside system32 folder of windows. That means anywhere, just anywhere.
You can write to a file with AIR only if the file is under "applicationStorageDirectory".
This is the only folder that has write permision.
If some know more please correct me.

Resources