|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
app.configI am using VS.NET 2003 and vb. I build my application MyApp and it generates MyApp.exe.config. So now MyApp.exe reads parameters from MyApp.exe.config. Great and no problem! I need to run the same program but with different configuration data. So I made a copy of MyApp.exe and MyApp.exe.config to put them in another folder and renamed the copy to MyApp2.exe and MyApp2.exe.config respectively. I ran it but it did not read from MyApp2.exe.config. I also renamed MyApp2.exe.config back to MyApp.exe.config and also did not work. (N.B. I need to have MyApp.exe and MyApp2.exe with different names). The question is: How can I make a copy of my program and its config file to another folder, and run both programs MyApp.exe and MyApp2.exe and each read from its own config file? Any help will be highly appreciated. Thanks Khodr If they're in different folders, why do you have to rename them? Just
leave them with their original names. Thanks Chris for ur reply. As I mentioned, I need to have them with
differnet names. They both stay running and if I need to kill one of them using Task Manager, the only way to know which one to kill is by the name. Again, is there a way to make them run both "with different names" at the same time. Thanks... Show quoteHide quote "Chris Dunaway" <dunaw***@gmail.com> wrote in message news:1141224019.800750.222000@t39g2000cwt.googlegroups.com... > If they're in different folders, why do you have to rename them? Just > leave them with their original names. > Can't you compile the program a second time with a different name?
Khodr wrote: Show quoteHide quote > Thanks Chris for ur reply. As I mentioned, I need to have them with > differnet names. They both stay running and if I need to kill one of them > using Task Manager, the only way to know which one to kill is by the name. > Again, is there a way to make them run both "with different names" at the > same time. Thanks... > > "Chris Dunaway" <dunaw***@gmail.com> wrote in message > news:1141224019.800750.222000@t39g2000cwt.googlegroups.com... >> If they're in different folders, why do you have to rename them? Just >> leave them with their original names. >> > > Yes I can compile "again" with different name. Just I was trying to see if
it can be easily done by simply copying and renaming. Why is it so complicated to have 2 copies of the same program running with different config files? What if I need to run 3 or more copies of the same program with different config files? Again, thanks for your reply. Show quoteHide quote "Jochen Albert" <meister-joc***@gmx.de> wrote in message news:du4dr9$j4m$1@news.cognex.com... > Can't you compile the program a second time with a different name? > > Khodr wrote: > > Thanks Chris for ur reply. As I mentioned, I need to have them with > > differnet names. They both stay running and if I need to kill one of them > > using Task Manager, the only way to know which one to kill is by the name. > > Again, is there a way to make them run both "with different names" at the > > same time. Thanks... > > > > "Chris Dunaway" <dunaw***@gmail.com> wrote in message > > news:1141224019.800750.222000@t39g2000cwt.googlegroups.com... > >> If they're in different folders, why do you have to rename them? Just > >> leave them with their original names. > >> > > > > You can strip the path information and .exe extension from Application.ExecutablePath with a regular
expression. Then use that string to create the name of your config file that you create and access. Regex reg = new Regex(@"(\w+)\.exe$"); string path = Application.ExecutablePath; string configname = reg.Matches(path)[0].Groups[1].Value + ".config"; This way if the executable is test1.exe it will create a config file called test1.config. ---Tome http://www.pcdotcom.com Show quoteHide quote On Wed, 1 Mar 2006 09:12:41 -0500, "Khodr" <khodr***@excite.com> wrote: >Hello, >I am using VS.NET 2003 and vb. I build my application MyApp and it generates >MyApp.exe.config. So now MyApp.exe reads parameters from MyApp.exe.config. >Great and no problem! > >I need to run the same program but with different configuration data. So I >made a copy of MyApp.exe and MyApp.exe.config to put them in another folder >and renamed the copy to MyApp2.exe and MyApp2.exe.config respectively. I ran >it but it did not read from MyApp2.exe.config. I also renamed >MyApp2.exe.config back to MyApp.exe.config and also did not work. (N.B. I >need to have MyApp.exe and MyApp2.exe with different names). > >The question is: How can I make a copy of my program and its config file to >another folder, and run both programs MyApp.exe and MyApp2.exe and each read >from its own config file? > >Any help will be highly appreciated. > >Thanks > >Khodr > Tome,
Here's a simple one line solution to get the config file name. string file = Assembly.GetEntryAssembly().Location + ".config"; Brian Tome wrote: Show quoteHide quote > You can strip the path information and .exe extension from Application.ExecutablePath with a regular > expression. Then use that string to create the name of your config file that you create and access. > > Regex reg = new Regex(@"(\w+)\.exe$"); > string path = Application.ExecutablePath; > > string configname = reg.Matches(path)[0].Groups[1].Value + ".config"; > > This way if the executable is test1.exe it will create a config file called test1.config. > > ---Tome > http://www.pcdotcom.com > Brian,
Assembly.GetEntryAssembly().Location Application.ExecutablePath Both give you the same results. You could indeed use the full path and just add .config. That would make test1.exe use a config file called test1.exe.config you could also use the full path and just replace the .exe with .config string configname = Application.ExecutablePath.Replace(".exe",".config"); or string configname = Assembly.GetEntryAssembly().Location.Replace(".exe",".config"); ---Tome http://www.pcdotcom.com Show quoteHide quote On 1 Mar 2006 08:27:01 -0800, "Brian Gideon" <briangid***@yahoo.com> wrote: >Tome, > >Here's a simple one line solution to get the config file name. > >string file = Assembly.GetEntryAssembly().Location + ".config"; > >Brian > Hi Guys,
Thanks for all your answers. After all this discussion: Is there a solution to my situtation "without" modifying my application and "without" recompiling? Simply, I want to run my program in more than one folder at the same time, but with different content of config file. The reason I need this, is that one version is pointing to Production and the other to Test. Thanks again Khodr "Tome" <t***@pcdotcom.com> wrote in message just add .config. Thatnews:8cjb025vlsmec7t597qp81fk9s97i2r4c5@4ax.com... > Brian, > > Assembly.GetEntryAssembly().Location > Application.ExecutablePath > > Both give you the same results. You could indeed use the full path and > would make test1.exe use a config file called test1.exe.config Assembly.GetEntryAssembly().Location.Replace(".exe",".config");> > you could also use the full path and just replace the .exe with .config > > string configname = Application.ExecutablePath.Replace(".exe",".config"); > or > string configname = Show quoteHide quote > > > ---Tome > http://www.pcdotcom.com > > > On 1 Mar 2006 08:27:01 -0800, "Brian Gideon" <briangid***@yahoo.com> wrote: > > >Tome, > > > >Here's a simple one line solution to get the config file name. > > > >string file = Assembly.GetEntryAssembly().Location + ".config"; > > > >Brian > > Khodr,
After re-reading your initial post. You shouldn't have a problem at all. It all depends on how you are loading your config file within your code. Can you please post a snippit showing how you load the config file? ---Tome http://www.pcdotcom.com Show quoteHide quote On Wed, 1 Mar 2006 13:21:08 -0500, "Khodr" <khodr***@excite.com> wrote: >Hi Guys, > >Thanks for all your answers. After all this discussion: Is there a solution >to my situtation "without" modifying my application and "without" >recompiling? > >Simply, I want to run my program in more than one folder at the same time, >but with different content of config file. The reason I need this, is that >one version is pointing to Production and the other to Test. > >Thanks again > >Khodr >"Tome" <t***@pcdotcom.com> wrote in message >news:8cjb025vlsmec7t597qp81fk9s97i2r4c5@4ax.com... >> Brian, >> >> Assembly.GetEntryAssembly().Location >> Application.ExecutablePath >> >> Both give you the same results. You could indeed use the full path and >just add .config. That >> would make test1.exe use a config file called test1.exe.config >> >> you could also use the full path and just replace the .exe with .config >> >> string configname = Application.ExecutablePath.Replace(".exe",".config"); >> or >> string configname = >Assembly.GetEntryAssembly().Location.Replace(".exe",".config"); >> >> >> ---Tome >> http://www.pcdotcom.com >> >> >> On 1 Mar 2006 08:27:01 -0800, "Brian Gideon" <briangid***@yahoo.com> >wrote: >> >> >Tome, >> > >> >Here's a simple one line solution to get the config file name. >> > >> >string file = Assembly.GetEntryAssembly().Location + ".config"; >> > >> >Brian >> > > Hi Tome,
That's how I get info from the config file: System.Configuration.ConfigurationSettings.AppSettings.Get(key) and it works very well with my original app, MyApp.exe with MyApp.exe.config Like I mentioned before, the problem is when I make a copy of this program in another folder and rename the copy to MyApp2.exe. Then it does not work. Thanks "Tome" <t***@pcdotcom.com> wrote in message It all depends on how younews:alpb0214n0sn6uk0h99uth5d2alrcn1qat@4ax.com... > Khodr, > > After re-reading your initial post. You shouldn't have a problem at all. Show quoteHide quote > are loading your config file within your code. Application.ExecutablePath.Replace(".exe",".config");> > Can you please post a snippit showing how you load the config file? > > ---Tome > http://www.pcdotcom.com > > > On Wed, 1 Mar 2006 13:21:08 -0500, "Khodr" <khodr***@excite.com> wrote: > > >Hi Guys, > > > >Thanks for all your answers. After all this discussion: Is there a solution > >to my situtation "without" modifying my application and "without" > >recompiling? > > > >Simply, I want to run my program in more than one folder at the same time, > >but with different content of config file. The reason I need this, is that > >one version is pointing to Production and the other to Test. > > > >Thanks again > > > >Khodr > >"Tome" <t***@pcdotcom.com> wrote in message > >news:8cjb025vlsmec7t597qp81fk9s97i2r4c5@4ax.com... > >> Brian, > >> > >> Assembly.GetEntryAssembly().Location > >> Application.ExecutablePath > >> > >> Both give you the same results. You could indeed use the full path and > >just add .config. That > >> would make test1.exe use a config file called test1.exe.config > >> > >> you could also use the full path and just replace the .exe with .config > >> > >> string configname = Show quoteHide quote > >> or > >> string configname = > >Assembly.GetEntryAssembly().Location.Replace(".exe",".config"); > >> > >> > >> ---Tome > >> http://www.pcdotcom.com > >> > >> > >> On 1 Mar 2006 08:27:01 -0800, "Brian Gideon" <briangid***@yahoo.com> > >wrote: > >> > >> >Tome, > >> > > >> >Here's a simple one line solution to get the config file name. > >> > > >> >string file = Assembly.GetEntryAssembly().Location + ".config"; > >> > > >> >Brian > >> > > > OKay... now I see what you're doing. You are using a System.Configuration .config file, not your
own. This should work without a problem. I've just tested it with VS2005 and c# and it worked without a hitch... I compiled the program as scrap.exe Created a new folder. Copied the program and the config file into the new folder. Renamed the executable to scrap2.exe Renamed the config file to scrap2.exe.config Modified the contents of scrap2.exe.config to have different data. Ran both programs simultaneously and received the proper results in each. It works fine for me. If you don't rename the config file, it will not work. It will populate the values with either "" or null value (unsure which one). I'm not sure why it's not working for you. What values is your program getting from your config file? Are they blank strings, or are they getting the wrong strings? ---Tome http://www.pcdotcom.com Show quoteHide quote On Wed, 1 Mar 2006 14:02:26 -0500, "Khodr" <khodr***@excite.com> wrote: >Hi Tome, > >That's how I get info from the config file: >System.Configuration.ConfigurationSettings.AppSettings.Get(key) > >and it works very well with my original app, MyApp.exe with MyApp.exe.config > >Like I mentioned before, the problem is when I make a copy of this program >in another folder and rename the copy to MyApp2.exe. Then it does not work. > >Thanks > > >"Tome" <t***@pcdotcom.com> wrote in message >news:alpb0214n0sn6uk0h99uth5d2alrcn1qat@4ax.com... >> Khodr, >> >> After re-reading your initial post. You shouldn't have a problem at all. >It all depends on how you >> are loading your config file within your code. >> >> Can you please post a snippit showing how you load the config file? >> >> ---Tome >> http://www.pcdotcom.com >> >> >> On Wed, 1 Mar 2006 13:21:08 -0500, "Khodr" <khodr***@excite.com> wrote: >> >> >Hi Guys, >> > >> >Thanks for all your answers. After all this discussion: Is there a >solution >> >to my situtation "without" modifying my application and "without" >> >recompiling? >> > >> >Simply, I want to run my program in more than one folder at the same >time, >> >but with different content of config file. The reason I need this, is >that >> >one version is pointing to Production and the other to Test. >> > >> >Thanks again >> > >> >Khodr >> >"Tome" <t***@pcdotcom.com> wrote in message >> >news:8cjb025vlsmec7t597qp81fk9s97i2r4c5@4ax.com... >> >> Brian, >> >> >> >> Assembly.GetEntryAssembly().Location >> >> Application.ExecutablePath >> >> >> >> Both give you the same results. You could indeed use the full path and >> >just add .config. That >> >> would make test1.exe use a config file called test1.exe.config >> >> >> >> you could also use the full path and just replace the .exe with .config >> >> >> >> string configname = >Application.ExecutablePath.Replace(".exe",".config"); >> >> or >> >> string configname = >> >Assembly.GetEntryAssembly().Location.Replace(".exe",".config"); >> >> >> >> >> >> ---Tome >> >> http://www.pcdotcom.com >> >> >> >> >> >> On 1 Mar 2006 08:27:01 -0800, "Brian Gideon" <briangid***@yahoo.com> >> >wrote: >> >> >> >> >Tome, >> >> > >> >> >Here's a simple one line solution to get the config file name. >> >> > >> >> >string file = Assembly.GetEntryAssembly().Location + ".config"; >> >> > >> >> >Brian >> >> > >> > > Tome, thanks again. This is really bugging me. I did the same same thing
like you did. It does not work... I will try to put some debug info to see why not it's not working.... "Tome" <t***@pcdotcom.com> wrote in message ..config file, not yournews:a3ub02dd3vmtq1s4eefp4ub7j37dptc8hf@4ax.com... > OKay... now I see what you're doing. You are using a System.Configuration > own. This should work without a problem. I've just tested it with VS2005 and c# and it worked> without a hitch... It works fine for me. If> > I compiled the program as scrap.exe > Created a new folder. > Copied the program and the config file into the new folder. > Renamed the executable to scrap2.exe > Renamed the config file to scrap2.exe.config > Modified the contents of scrap2.exe.config to have different data. > > Ran both programs simultaneously and received the proper results in each. > you don't rename the config file, it will not work. It will populate the values with either "" or> null value (unsure which one). getting from your config> > I'm not sure why it's not working for you. What values is your program > file? Are they blank strings, or are they getting the wrong strings? MyApp.exe.config> > ---Tome > http://www.pcdotcom.com > > On Wed, 1 Mar 2006 14:02:26 -0500, "Khodr" <khodr***@excite.com> wrote: > > >Hi Tome, > > > >That's how I get info from the config file: > >System.Configuration.ConfigurationSettings.AppSettings.Get(key) > > > >and it works very well with my original app, MyApp.exe with Show quoteHide quote > > > >Like I mentioned before, the problem is when I make a copy of this program > >in another folder and rename the copy to MyApp2.exe. Then it does not work. > > > >Thanks > > > > > >"Tome" <t***@pcdotcom.com> wrote in message > >news:alpb0214n0sn6uk0h99uth5d2alrcn1qat@4ax.com... > >> Khodr, > >> > >> After re-reading your initial post. You shouldn't have a problem at all. > >It all depends on how you > >> are loading your config file within your code. > >> > >> Can you please post a snippit showing how you load the config file? > >> > >> ---Tome > >> http://www.pcdotcom.com > >> > >> > >> On Wed, 1 Mar 2006 13:21:08 -0500, "Khodr" <khodr***@excite.com> wrote: > >> > >> >Hi Guys, > >> > > >> >Thanks for all your answers. After all this discussion: Is there a > >solution > >> >to my situtation "without" modifying my application and "without" > >> >recompiling? > >> > > >> >Simply, I want to run my program in more than one folder at the same > >time, > >> >but with different content of config file. The reason I need this, is > >that > >> >one version is pointing to Production and the other to Test. > >> > > >> >Thanks again > >> > > >> >Khodr > >> >"Tome" <t***@pcdotcom.com> wrote in message > >> >news:8cjb025vlsmec7t597qp81fk9s97i2r4c5@4ax.com... > >> >> Brian, > >> >> > >> >> Assembly.GetEntryAssembly().Location > >> >> Application.ExecutablePath > >> >> > >> >> Both give you the same results. You could indeed use the full path and > >> >just add .config. That > >> >> would make test1.exe use a config file called test1.exe.config > >> >> > >> >> you could also use the full path and just replace the .exe with ..config > >> >> > >> >> string configname = > >Application.ExecutablePath.Replace(".exe",".config"); > >> >> or > >> >> string configname = > >> >Assembly.GetEntryAssembly().Location.Replace(".exe",".config"); > >> >> > >> >> > >> >> ---Tome > >> >> http://www.pcdotcom.com > >> >> > >> >> > >> >> On 1 Mar 2006 08:27:01 -0800, "Brian Gideon" <briangid***@yahoo.com> > >> >wrote: > >> >> > >> >> >Tome, > >> >> > > >> >> >Here's a simple one line solution to get the config file name. > >> >> > > >> >> >string file = Assembly.GetEntryAssembly().Location + ".config"; > >> >> > > >> >> >Brian > >> >> > > >> > > > Hi Tome and Hi to all,
Finally, I resolved this puzzle. You won't believe it. What I did that caused all the trouble: MyApp.exe is in a folder called: "C:\MyFolder\" 1) so I copied it along with MyApp.exe.config to "C:\MyFolder (TEST)\" 2) renamed MyApp.exe to MyApp-TEST.exe 3) renamed MyApp.exe.config to MyApp-TEST.exe.config Result: FAILURE SOLUTION: I renamed the "folder" itself "C:\MyFolder (TEST)\" to "C:\MyFolder-TEST\" Now it works. Can you believe it? It did not like the "(" and ")" in the folder name itself. Thank you all... Khodr Show quoteHide quote "Khodr" <khodr***@excite.com> wrote in message <briangid***@yahoo.com>news:e62JS3ZPGHA.1460@TK2MSFTNGP10.phx.gbl... > Tome, thanks again. This is really bugging me. I did the same same thing > like you did. It does not work... I will try to put some debug info to see > why not it's not working.... > > > > "Tome" <t***@pcdotcom.com> wrote in message > news:a3ub02dd3vmtq1s4eefp4ub7j37dptc8hf@4ax.com... > > OKay... now I see what you're doing. You are using a System.Configuration > .config file, not your > > own. This should work without a problem. I've just tested it with VS2005 > and c# and it worked > > without a hitch... > > > > I compiled the program as scrap.exe > > Created a new folder. > > Copied the program and the config file into the new folder. > > Renamed the executable to scrap2.exe > > Renamed the config file to scrap2.exe.config > > Modified the contents of scrap2.exe.config to have different data. > > > > Ran both programs simultaneously and received the proper results in each. > It works fine for me. If > > you don't rename the config file, it will not work. It will populate the > values with either "" or > > null value (unsure which one). > > > > I'm not sure why it's not working for you. What values is your program > getting from your config > > file? Are they blank strings, or are they getting the wrong strings? > > > > ---Tome > > http://www.pcdotcom.com > > > > On Wed, 1 Mar 2006 14:02:26 -0500, "Khodr" <khodr***@excite.com> wrote: > > > > >Hi Tome, > > > > > >That's how I get info from the config file: > > >System.Configuration.ConfigurationSettings.AppSettings.Get(key) > > > > > >and it works very well with my original app, MyApp.exe with > MyApp.exe.config > > > > > >Like I mentioned before, the problem is when I make a copy of this > program > > >in another folder and rename the copy to MyApp2.exe. Then it does not > work. > > > > > >Thanks > > > > > > > > >"Tome" <t***@pcdotcom.com> wrote in message > > >news:alpb0214n0sn6uk0h99uth5d2alrcn1qat@4ax.com... > > >> Khodr, > > >> > > >> After re-reading your initial post. You shouldn't have a problem at > all. > > >It all depends on how you > > >> are loading your config file within your code. > > >> > > >> Can you please post a snippit showing how you load the config file? > > >> > > >> ---Tome > > >> http://www.pcdotcom.com > > >> > > >> > > >> On Wed, 1 Mar 2006 13:21:08 -0500, "Khodr" <khodr***@excite.com> wrote: > > >> > > >> >Hi Guys, > > >> > > > >> >Thanks for all your answers. After all this discussion: Is there a > > >solution > > >> >to my situtation "without" modifying my application and "without" > > >> >recompiling? > > >> > > > >> >Simply, I want to run my program in more than one folder at the same > > >time, > > >> >but with different content of config file. The reason I need this, is > > >that > > >> >one version is pointing to Production and the other to Test. > > >> > > > >> >Thanks again > > >> > > > >> >Khodr > > >> >"Tome" <t***@pcdotcom.com> wrote in message > > >> >news:8cjb025vlsmec7t597qp81fk9s97i2r4c5@4ax.com... > > >> >> Brian, > > >> >> > > >> >> Assembly.GetEntryAssembly().Location > > >> >> Application.ExecutablePath > > >> >> > > >> >> Both give you the same results. You could indeed use the full path > and > > >> >just add .config. That > > >> >> would make test1.exe use a config file called test1.exe.config > > >> >> > > >> >> you could also use the full path and just replace the .exe with > .config > > >> >> > > >> >> string configname = > > >Application.ExecutablePath.Replace(".exe",".config"); > > >> >> or > > >> >> string configname = > > >> >Assembly.GetEntryAssembly().Location.Replace(".exe",".config"); > > >> >> > > >> >> > > >> >> ---Tome > > >> >> http://www.pcdotcom.com > > >> >> > > >> >> > > >> >> On 1 Mar 2006 08:27:01 -0800, "Brian Gideon" Show quoteHide quote > > >> >wrote: > > >> >> > > >> >> >Tome, > > >> >> > > > >> >> >Here's a simple one line solution to get the config file name. > > >> >> > > > >> >> >string file = Assembly.GetEntryAssembly().Location + ".config"; > > >> >> > > > >> >> >Brian > > >> >> > > > >> > > > > > >
Invalid Cast Exception using Inherited Object
DateTimePicker - Howto set the language SQL Server or ACCESS? String Concatenation PC to PC file transfer Save and Load a TreeView to SQL Database Client- Server Programming using VB.NEt & SQL SERVER Referencing the Assembly GUID How to hide the dialog form? Limit Columns shown from XML file |
|||||||||||||||||||||||