Hi
Am using VB.Net on Visual Studio 2008 with .Net Framework 3.5 SP1
I am deploying my application using clickonce with the application available offline as well. The application is set as single instance and sets up a file association.
The application loads files launched from our document management system (process.start (\\servername\documents\docname1.quo")
In the Startup event of ApplicationEvents I can access the filename using
Dim formPath As String = String.Empty
If AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0 Then
For Each arg As String In AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData
If arg.StartsWith("file") Then
Dim file As New Uri(arg)
formPath = file.LocalPath
End If
Next
End If
However when launching subsequent files, trying to access the filname using the same code in the StartupNextInstance event does not work, it returns the original filename again.
Having spent a while searching on this it seems that it was logged as a bug at one time, but later cancelled as being by design.
Could anyone help with a way of doing this, or indeed a suitable workaround.
Kind Regards
Nic
| | NicPye Monday, August 17, 2009 2:32 PM | Ok, I did a little more research on this. Here's the deal. When you double-click on a Word document, it opens Microsoft Word and shows your document.
If you are targeting .Net 3.5, you can specify a file extension to be associated with your application. WHen you do that, and the user double-clicks on a file with that extension, it starts up your application.
If you allow multiple instances of your application to run, fine. But if you want to have one application that accepts multiple documents, much like Microsoft Word, you are going to have to handle it.
I looked at my company's application (written in C#), and someone put in some code to handle the single instance requirement that uses named pipes and some interprocess communication to tell that the application is already running. If it's running, it sends a message to the running process to display itself front and center, rather than starting up another instance. I did some testing, and when it starts it up a second time, it does of course have the ability to pull the file name. So if I put this into our application, I would have it include the file name in the message it sends to the running instance.
It looks similar to the code found in these articles: http://www.codeproject.com/KB/cs/cssingprocess.aspx http://www.codeproject.com/KB/threads/dotnetnamedpipespart1.aspx http://www.codeproject.com/KB/threads/dotnetnamedpipespart2.aspx
Ours looks like a combination of the three. Where it raises the other process in singleinstance, ours uses the interprocess stuff to connect and restore the already-running application. At that point, I can see the file name in the second running instance, and this is where I would send a message to the already-running instance with the file name.
RobinDotNet
Click here to visit my ClickOnce blog!- Marked As Answer byAland LiMSFT, ModeratorFriday, August 21, 2009 6:09 AM
-
| | RobinDotNet Thursday, August 20, 2009 4:23 AM | Let me see if I can restate the problem. You have deployed your application as an online-only application, and want to pass query parameters to it when it starts up, is that right? If that's the case, you must deploy it to a web server, it won't work when deployed to a file server, which it looks like you are doing, from the information you provided. RobinDotNet Click here to visit my ClickOnce blog! | | RobinDotNet Tuesday, August 18, 2009 7:23 AM | No, the application is available offline as well. File association is set up with the application, (.quo file extention). The application is set as a single instance application. If in windows explorer you double click a .quo file, the application opens as expected, and the MyApplication_Startup method of ApplicationEvents correctly gathers the path of the .quo filename from the ActivationData.
When starting an additional .quo file, as expected the StartupNextInstance event is fired, but the path returned in ActivationData is the path of the original .quo file, not the second one.
There is a workaround suggested there, but it involves turning off Application Framework which was something i washopingto avoid.
Nic | | NicPye Tuesday, August 18, 2009 8:05 AM | I have done this in our application just for demoing at .NET User Group meetings, and I'm not having any problems with it picking up different files every time I run it. I do have to make sure the application isn't running before trying the next file. Here is the code I am using, in case that helps.
private static void GetFileDoubleClicked(gmManager gmMgrIn)
{
// Get the ActivationArguments from the SetupInformation property of the domain.
ActivationArguments args = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
if (args.ActivationData != null && args.ActivationData.Length > 0)
{
foreach (string arg in args.ActivationData)
{
string filename = arg.Replace("%20", " ");
filename = filename.Replace(@"file:///", string.Empty);
if (File.Exists(filename))
{
//handle the file
DoWhatever(filename);
}
else
System.Diagnostics.Debug.Print("Can't find file {0}.", filename);
}
}
else if (args.ActivationData == null)
{
System.Diagnostics.Debug.Print("NO ARGUMENTS passed in");
}
else
{
System.Diagnostics.Debug.Print("ActivationData.Length = {0}", args.ActivationData.Length);
}
}
Try this and see if it makes any difference whatsoever. I don't know why it would work for some people, but not others. I am building using VS2008 with SP-1, and of course this version of our application targets .NET 3.5 SP-1. RobinDotNet Click here to visit my ClickOnce blog! | | RobinDotNet Tuesday, August 18, 2009 11:13 PM | I am grateful for your help, i am away from my code at the moment so will try later, but i am not sure this will work if you say you have to close the application before trying the next file, it kinda defeats the object of a single instance app!
I can also succesfully get the first filename, it is exactly the problem that i cant get any subsequant filenames. It just seems a little odd that there is a startupnextinstance event yet it returns the activation data associated with the original startup.
Kind Regards
Nic | | NicPye Wednesday, August 19, 2009 11:19 PM | Ok, I did a little more research on this. Here's the deal. When you double-click on a Word document, it opens Microsoft Word and shows your document.
If you are targeting .Net 3.5, you can specify a file extension to be associated with your application. WHen you do that, and the user double-clicks on a file with that extension, it starts up your application.
If you allow multiple instances of your application to run, fine. But if you want to have one application that accepts multiple documents, much like Microsoft Word, you are going to have to handle it.
I looked at my company's application (written in C#), and someone put in some code to handle the single instance requirement that uses named pipes and some interprocess communication to tell that the application is already running. If it's running, it sends a message to the running process to display itself front and center, rather than starting up another instance. I did some testing, and when it starts it up a second time, it does of course have the ability to pull the file name. So if I put this into our application, I would have it include the file name in the message it sends to the running instance.
It looks similar to the code found in these articles: http://www.codeproject.com/KB/cs/cssingprocess.aspx http://www.codeproject.com/KB/threads/dotnetnamedpipespart1.aspx http://www.codeproject.com/KB/threads/dotnetnamedpipespart2.aspx
Ours looks like a combination of the three. Where it raises the other process in singleinstance, ours uses the interprocess stuff to connect and restore the already-running application. At that point, I can see the file name in the second running instance, and this is where I would send a message to the already-running instance with the file name.
RobinDotNet
Click here to visit my ClickOnce blog!- Marked As Answer byAland LiMSFT, ModeratorFriday, August 21, 2009 6:09 AM
-
| | RobinDotNet Thursday, August 20, 2009 4:23 AM |
|