views:

28

answers:

3

I'm making a Word 2007 add-in with C# 4.0 in Visual Studio 2010. I need an Access 2007 database (a .accdb file) to be placed in the data directory by the clickonce installer. Unfortunately, the file is getting put elsewhere, so the application can't find it at runtime. I've seen various articles refer to using the Application Files dialog on the Publish tab of the project properties to mark the file as a data file, but I have no Application Files button for some reason.

Any idea how to make the Application Files dialog appear, or some other way to manually mark my .accdb file as a data file?

+1  A: 

In the Solution Explorer, if you set the file's property to be Copy to Output Directory = Copy Always. Then when you go to Application Files they should default as a Data File.

However, since this is your database I would consider looking at make it safe across updates so you might consider this post.

See http://msdn.microsoft.com/en-us/library/dd465298.aspx

By the way, "Application Files" button should be on the project properties' Publish tab.

Reddog
There is no Application Files button on the Publish screen for a VSTO application.
RobinDotNet
Unfortunately, Visual Studio will only mark files with certain extensions as data files (e.g., .xml, .mdb, some others). .accdb is not one of them. So whiile I do have Copy to Output Directory = Copy Always, this puts it in with the application files, not the data files.I was able to get things to work by using the Mage tool as described here: http://msdn.microsoft.com/en-us/library/6fehc36e.aspxThe trick with MageUI is it's open file dialog assumes you want to open a manifest associated with a .exe; a vsto project has a .dll, so the manifest doesn't appear in the files list by default.
Bob
Oh shoot! Sorry then! Well in a non-VSTO project that's how it'll work... Learn something new every day.
Reddog
A: 

VSTO Applications do not have the Application Files button available, and you can't set the file types specifically. If your file is not being deployed to the data directory and you want it to be, rename it with a file extension that is marked by ClickOnce as data. This includes .xml, .mdb, and .mdf. Otherwise, the file is deployed with the VSTO application and will be in the same location as the rest of the files.

The location of the deployment files for a VSTO application can be discovered programmatically this way:

System.Reflection.Assembly.GetExecutingAssembly.CodeBase

You might want to move the database, though, because unless you deploy it as data, it will be lost when an update is performed. Or you can check out this article about where to put your data to keep it safe from ClickOnce updates.

RobinDotNet
A: 

I was able to get things to work by using the Mage tool as described here:

msdn.microsoft.com/en-us/library/6fehc36e.aspx

The trick with MageUI is it's open file dialog assumes you want to open a manifest associated with a .exe; a vsto project has a .dll, so the manifest doesn't appear in the files list by default, which was really tripping me up.

Basically, this process is a pain because you have to remember to do it manually. I don't know if there's a way to make this part of the build (maybe a post-build step? But this is really a post-publish step).

Bob
If the user is updating information in your database, you still might want to check out the article above about how to keep your data safe from ClickOnce updates.
RobinDotNet
Do the updates overwrite the contents of the data directory?
Bob
No, they create a whole new directory for the new version. If you have it deployed as a data file, it should copy it forward to the new folder. The thing about that is if the time stamp changes at all on the file you are deploying, it will install the new one and copy the old one to the .\pre folder under the data folder, and you have to handle moving the data from the old database to the new. That's too risky a chance for me to take, so we move the database. Check out this link: http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/c8c55be6-be34-47cf-93fc-6cc0bf97f2cf
RobinDotNet
@Bob: Good to here this is resolved. You can go ahead and accept your own answer as the correct one.
Otaku
Bob -- you don't have to do it manually; check my answer above.
RobinDotNet