Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > How can I get the data directory when clickonce-app's exe file is started from other application?
 

How can I get the data directory when clickonce-app's exe file is started from other application?

I am currently building an application A that will be deployed via click once. It will be used as a stand-alone application. Additionally, a (legacy) third-party application B will start my application in certain cases. To this end, A will, when first run, write the path to its exe file in B's ini file, and B will start A by executing the exe file.

The problem is that A frequently downloads data updates from the web and stores them locally. For this, I am currently using ApplicationDeployment.CurrentDeployment.DataDirectory
which works fine when A is started via the start menu. When the exe file is started directly, however, this is not set.

Is there any way, when the exe file is started directly, to find out the clickonce data directory for my application?

If not: How can I make sure that A will operate on the same data, regardless of being started via start menu or exe file? I could, of course, just use a folder 'C:\AppA\Data', but that would be very bad style and cause problems with permissions for obvious reasons.

Any suggestions anyone?
Christian Korn  Thursday, September 03, 2009 6:58 AM
Hi Christian,

I think we have several options here:

1. Use the Environment.GetFolderPath method with SpecialFolder.ApplicationData to get the system defined application data directory path and store your data there. However, there could be security permission issues depending on your ClickOnce deployment security configuration.

2. Use IsolatedStorage to store your data file. Your application will require IsolatedStorageFilePermission if running as partially trusted.

3. Modify your application to check itself at startup, if found it was not started by ClickOnce stub, just start a new instance of itself via the ClickOnce shortcut and exit the current one.

You may also want to refer to this article for some detailed explanations: Accessing Local and Remote Data in ClickOnce Applications.

Best regards,
Jie
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

If you have any feedback, please tell us.

The CodeFx Project
My Blog (in Simplified Chinese)
Wang, Jie  Thursday, September 03, 2009 10:12 AM
You don't want your third party application to run your ClickOnce application by invoking the exe. If you do, it won't run it as a ClickOnce application, and won't pick up the updates, and the ClickOnce attributes like DataDirectory won't be set.

What you need to do is just search the start menu for the shortcut and do a process.start on it in order to run it.

shortcutName =string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs),
"\\", PublisherName, "\\", ProductName, ".appref-ms");

where PublisherName and ProductName are the same as those entries in the Options for your ClickOnce application, i.e. the entries on the start nenu.

You might want to check to make sure the shortcut exists before calling process.start on it, just in case the user doesn't have it installed, or has uninstalled it or something. Andif it's not installed, you can have your second program install it by doing Process.Start("iexplore.exe", url_to_setup.exe_file);

RobinDotNet



Click here to visit my ClickOnce blog!
RobinDotNet  Saturday, September 05, 2009 5:48 PM
1. He can't get the application data folder unless he is running the application as a ClickOnce application, which it doesn't do when running the exe directly.

2. He can't find the data file in order to move it if he's not running it as a ClickOnce application. Also, the recommended location for retaining external data outside of a ClickOnce deployment is LocalApplicationData, not IsolatedStorage.

3. It's more straightforward and less confusing to the user to just invoke the ClickOnce shortcut from the second application directly.

RobinDotNet
Click here to visit my ClickOnce blog!
RobinDotNet  Saturday, September 05, 2009 5:50 PM

You can use google to search for other answers

Custom Search

More Threads

• Hooking into ClickOnce Application
• ClickOnce deployment and EventLogInstaller
• Values of Public Keys Don't match
• Packaging Registry File
• Servername parameter in custom action
• Application has stopped working...?
• help with deployment - mshtml.dll
• Windows Installer Issue
• Error :: MsiInstallProduct returned '1638' .
• Distributing DLLs as shared side-by-side assemblies