Embed SQL .BAK file with WPF Clickonce Deployment - c#

In the first installation in my WPF application I checked if the SQL database for my application exist or not, If not the application restore it from .bak SQL file.
When I publish my application I can't attach (Embed) the .bak file.
How can I do that ?
Thanks in advance
Abdusalam

Well .. I got the solution :
One good way of doing this is:
Create a folder under the app in VS name e.g. "datafiles"
Add all files to that folder using Add as link in the dialog box after selecting Add existing item on the folder
Mark all files as Copy if newer (Copy to output directory property)
Make sure the build action is content
--> when you publish the files will be put in that folder and be a part of the application installation
Good luck!
Source

Related

WPF Publish - include folders

I have a WPF project that is now finished, and I want to publish the app into an installer that other people can use.
When I publish the project, the project compiles into setup.exe, but on install the folders that I have do not get included.
I've been reading the guides, and made sure to include the files inside the folders as Content or a Resource. I've also made sure they are always copied. When some of my files are copied, they have a .deploy extension, and I need it to be an .xml in order for some function to read them. Images that I have in the app load fine however.
What do I need to do to have my custom files be EXACTlY as they are, xml as xml, txt as txt and so on. Also I have some empty folders, like this TempCF that I use at some point. Do i need to create it via code?
If you go to Project->Properties->Publish->Install Mode and Settings->Options->Deployment in Visual Studio, there is a "Use ".deploy" file extension" option that you can untick to get rid of the .deploy extension being added to your published files:
Empty project folders are not included in the output. Either put a dummy content file in them or create the folder dynamically as needed during runtime.
# Nikola L.
You could try to use the following methods to add the files in your program to the installation package so that you can have the files you need in your installation path. If I misunderstood your question, please let me know.
The steps are as follows:
1.Right-click on the Setup project and select View -> File System
2.In the File System page, right-click the Application Folder (File System on target Machine) and select Add->Folder(named User's Application Data ) -> Fileā€¦-> find the file under your project and select the file you need.
Such as:
3.Right-click the Setup project.
Install your setup package.
You can find the files you added in your installation path.
The result is like the picture below:

How to add SQLite .db into C#.NET project

I just started to learn C#, and currently trying to create a simple program that read 1 row of data from SQLite database.
I've successfully created the program, but i still have to refer to the .db file with full address like :
SQLiteConnection("Data Source=C:/Users/../SQLiteStudio/dbs/mk_ii.db; Version=3;")
But this way, the .db won't be included when i create an installer. I want to make it something like when i add an image to my Solution Explorer, i can use short address like :
res/img/logo.png --i also have copy of .db file in res/ folder
So, is there any way to include the .db file to my project? I've tried to read current directory and using |DataDirectory|, but all of those referred to the .exe file's active folder, and didn't work when i debugging since when debugging the .exe file have different directory than the project directory.
For a note, i'm using VS Community 2015 and System.Data.SQLite. Also i've tried added the .db file to Solution Explorer, but i can't seem to access through it.
Include your database file in your project. Set the type to Content, that will make sure the file is copied to your output directory. Use relative path in connection string.

Create installer for winForms with local DB

I have a Winforms application (checkers game) which have a local DB (using SQL Server Express)
to save the registered players and their scores..
I'm trying to create an installer for this app by this tutorial
Everything is fine, but when I'm trying to add the players I'm getting a SQL error
that says the database wasn't found.. so how can I add the local DB (.mdf file) to the installer?
Provided that the conditions to use local DB at the client machine are OK (see LocalDB deployment on client PC), in the deployment project you can just add the database files to the application folder (Choose File System Editor in the solution explorer when the deployment project is selected.
Side note: Are you aware of the fact that in VS2012 the MSI deployment project template is deprecated?
Addition: And it's back in VS 2013!
This is my workaround in wpf. I think solution is the same in Winform:
Make your mdf file "content" by right clicking on that and select properties. In "build action" menu select "content". And in copy to output directory select copy always
In Solution explorer go to Properties/Settings.Settings and put connection strings in a field (notice that name of that must be the same as it is in your App.config (eg in wpf) like picture below it will create).
Right click in your setup project and Add->Project output-> then select content files.

Link to config file in .Net setup project

I am creating an installer for my C# application, and I want to put a link to the configuration file into the start menu, so that users can open it for editing in notepad from the program folder in the start menu.
I seem not to be able to put a link to it however - does anyone know how to do this? (Really, I would just love to put "[targetdir]\myapp.exe.config but VS doesn't let me edit the field, only select from a file browser).
Many thanks,
Rob
I found the solution and it's pretty easy:
Add Project Output for your project in the setup project
Select Project Output from File System in left pane and go to the properties of the project output. Then add a filter *.config to remove the .config file from your project output.
Rename the app.config from your actual project to the output name that your App exe ([ProductName]) will have along with the config extension ofcourse.
Add the [ProductName].config to your setup project as a File.
Create a Shortcut to that file and add it in any setup folder desktop or program folder.
Voila.
You're all set.
Isn't the config file added in your installer? You should be able to select it when prompted for the shortcut target (the "Select Item in Project" dialog). Please note that in this prompt dialog you first need to browse to the folder which contains it (for example double-click "Application Folder").
If the config file is not added, you need to manually add it in "Application Folder". Only then you can create a shortcut to it.
Please note that Visual Studio doesn't support shortcuts to a specific file from a project output which generates multiple files. In this case you can try using a custom action which creates the shortcut through custom code.
I remember doing it in Vs2005 using as below:
File System Editor > Users Programs Menu
Add> Folder
Add file (Say Config file) point it to the its location

How do I add files to a windows mobile device when deploying it?

I have a number of images and a CSV data file that I want to deploy to a windows mobile device along with my application. I'm using Visual Studio 2008 and C#.
I've added a "Content" folder to my project which contains the bmp images and the CSV file. When running my program on the emulator (by hitting F5) only the app is deployed, and not the "Content" directory.
I know I can add images to the resource file, but that isn't what I want to do - I want the images to actually be available on the device so that they can be changed without having to deploy a new application.
So my question is how can I set it up so that the "Content" directory is copied to the device?
Thanks in advance!
THe files from a "Content" folder will not be deployed on your device.
In order to deploy a file, right click it -> Properties -> select "Content" from Build Action
Are the files within that folder also marked as content?
In order to deploy files in the content folder along with folder,
Follow the below procedure,
Right Click the files inside Content folder--> select Propeties-->Build Action-->set build action as "Content" --> Copy to output directory--> set Copy always or Copy if newer.
Like this Do changes to all type of files(.csv,bmp etc)
Then Finally deploy into emulator or native device.
You will see the all files appearing on the program directory of emulator or device.
Happy Coding -:)

Categories