I have an application that is a windows application and requires a file which contains profile information for an emulator. How can this file get added to the clickonce package so the file is installed when the application is installed. This is actually a file that can be executed so I also need to know what the path would be. Any ideas

How to add a file to a clickonce deployment?
Vinay Kittur
Here is a good resource: http://msdn2.microsoft.com/en-us/library/kzy0fky2.
Regards,
Elizabeth Maher
nanci ruhl
I can follow how to set up all the application files to include them as content.
However, what I still need to learn / understand is how to reference these content files from within my application. i.e. how to create the relative paths for all these files. Are there other resources / tutorials on how to reference project content
Couple more questions:
a) I presume this will work for any type of file (I need to include text, graphics and additional EXEs (which will called by my application)
b) Do I need to use the same method to include the application's database
c) Is the above different to using project resources
MRW
khani
Dim instance As ApplicationDeployment
Dim value As String
value = instance.DataDirectory
so in my example above, i'd use instance.DataDirectory & "file.xml"
Is there a thorough complex deployment example available anywhere
-Jim
Todd Hobdey
If there is a better way to do this, I'd like to know, but this certainly worked for me in a project with about 50 data files. I figured it out through trial and error, but i was unable to find any documentation to support it.
As far as needing to know the path of the file, add code to the project that will write a key to the registry upon execution of your main exe. You should know the relative path between the two, so this should work out for you.
Jim
Rafael Sancho
b) Almost. The Build Action property should be set to Content. However, if you want the ability to upgrade the application database (which I assume is a local database file) then the Publish Status of the file needs to be set to Data File. The Publish Status of a file may be set on the Application Files dialog, found of the Publish Property Page. If you don't care about the ability to upgrade your data, then setting the Publish Status of the file to Include will also work.
c) If you are using an .mdf file for your application data store, then everything will 'just work'. You will have to upgrade the application database, if needed. Previous version of the database are put into the DataDirectory\.pre folder while the new database is put in the DataDirectory. Here is a link describing the DataDirectory: http://msdn2.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.datadirectory.aspx
If you are using an xml file, then the data will have to be read in using code, as Jim showed.
Regards,
Elizabeth Maher
Flavious
Project Database Deployment< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
My comments from the previous post referred to an .mdf that is included in the project. If your database is external, then nothing about the datastore applies. The connection string used during development will still apply when the application is published.
Application.StartupPath versus DataDirectory
No, these do not point to the same place. Use DataDirectory for any files with a Publish Status of ‘Data File’ in the Application Files Dialog. Use Application.StartupPath for files with the Publish Status of ‘Include’ in the Application Files Dialog.
INCLUDE statements required
My guess is Jim is referring to database files included in the project.
Relative paths (at design time)
I don’t know how to get the relative path PictureBox.ImageLocation to work at design time. I would suggest posting your question to the Windows Forms Designer Forum (http://forums.microsoft.com/MSDN/ShowForum.aspx ForumID=5&SiteID=1). When I set the ImageLocation property to Graphics\MyImage.jpg, everything worked during runtime.
If you are just trying to set the image of a picture box in a way that it can be seen at design and runtime, I suggest using the Image property. You can import a picture and it will be saved in the resources for the form.
BarendJ
One more question:
I tried including my external database and two exe files in the Application Files Dialog.
When I did a "publish" these did not get copied to the target publish folder.
Will Application Files only get copied as part of the publish process if they are specifically referred in the code by a my.resources statement
I can get the file for the types supported working no problem. Its just the .exe and the external .mdb I am having trouble with.
Ermac
Lots more questions then:
a) Project database deployment. Yes, I am using a .mdf, but its external to my project and does not appear to get included in the ClickOnce deployment. I am not using it for application/config data per se, its the main database for the solution.
"If you are using an .mdf file for your application data store, then everything will 'just work'." Does only apply for a database that included in the project or being used for application/set-up data
"You will have to upgrade the application database, if needed." Not sure what you mean here.
"Previous version of the database are put into the DataDirectory\.pre folder while the new database is put in the DataDirectory." Are you referring to a situation where the database in automatically updated via the ClickOne method I don't think I need this. All I want is the ability to deploy the initial, empty database. Once deployed it will then take on a life of its own as it becomes full of data specific to the deployment.
b) Application.StartupPath versus DataDirectory. Do these not point to the same place Which one is preferable
i.e. Use StartupPath for referencing text, xml, graphics etc
Use DataDirectory for referencing the database location
c) INCLUDE statements required
"Yes, just have them included in the top level of your project" Jim, do you imply that I also need to add some type of "INCLUDE" statement to establish the link to these files in my application
c) Relative paths (at design time). I notice from the example above that you are using "\" in the relative path definition. I was under the impression that relative paths need a "/" (Or is this only for HTML )
I can not get relative paths to work when using them even in a very simple manner. See below an extract from another post I have running concurrently with this one. Trying to get a .jpg to be the default ImageLocation for a pictureBox.
Using the Solution Explorer I have added a folder to my project. So I have MyProject\Graphics
I have then added the graphics file to this folder and set its properties to "copy always".
So I have Myproject\Graphics\MyImage.jpg
Then I have a included a picturebox1 on my windows form in the design view.
So, I go to the properties and want to add in the relative path to MyImage.jpg.
I have tried setting ImageLocation property to:
/Graphics/MyImage.jpg
Graphics/MyImage.jpg
../Graphics/MyImage.jpg
./Graphics/MyImage.jpg
MyProject/Graphics/MyImage.jpg
/MyProject/Graphics/MyImage.jpg
etc etc
None of the above appear to work. (I have also tried the backslash options as well)
What am I doing wrong Can someone point out how I should be setting up relatives paths is Visual Basic please
Thanks for all the help thus far.
PS. Note that the
Dim Value As String
PPS. Yes, more detailed deployment examples would be appreciated.
Jason Beheler
a) Yes, just have them included in the top level of your project
b) Yes
c) I'm not sure what you mean
The following is how i read data out of a .xml file:
Imports System.io
Private Shared m_StandardData As DataSet
Public Shared ReadOnly Property StandardData() As DataSet
Get
If m_StandardData Is Nothing Then
m_StandardData = New DataSet
m_StandardData.ReadXml(Application.StartupPath & "\Data\Standards.xml")
End If
Return m_StandardData
End Get
End Property
Ross William Nelson
If the file is not part of your project, you have two options.
1. Add the file to your project using Add -> Existing Item off the context menu for the project node in the Solution Explorer.
2. Add a "link" to the external file. (Warning: this will make your project less portable.) Add the following xml to your project file.
<ItemGroup>
<Content Include="..\OutsideTextFile1.txt" />
</ItemGroup>
For a files you described to be pubished:
1. The files must be included in the main project.
2. The Build Action must be set to Content
3. The Publish Status must be set to 'Include' or 'Data File'
If this information does not help you, could you post your project file so I can help you trouble shoot. I just need the two sections: 1) the section that describes the files and references in the project 2) the section that describes the publish files.
Best Regards,
Elizabeth Maher
Blu_Fire739
If using vb, the code would look like:
Dim pathToXmlFile As String
If My.Application.IsNetworkDeployed Then
pathToXmlFile = IO.Path.Combine(My.Application.Deployment.DataDirectory, "file.xml")
Else
pathToXmlFile = IO.Path.Combine(Application.StartupPath, "file.xml")
End If
If using C#, the code would look like:
string pathToXmlFile;
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed){
pathToXmlFile = System.IO.Path.Combine(System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory, "file.xml");
}else{
pathToXmlFile = System.IO.Path.Combine(Application.StartupPath, "file.xml");
}