Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2007, 06:37 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Doug,

Where in this thread does it say anything about what kind of app this poster is building. That hasn't been stated anywhere. I assume it's a windows app, you are assuming it's a web app. It is not clear.

semilemon,

What kind of application is this?

-Peter
 
Old April 22nd, 2007, 06:29 PM
Authorized User
 
Join Date: Apr 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, maybe I wasn't clear enough. Let me explain this program.

Its called AutoVocab. Basically, the user enters a list of words they would like the definitions for, and autovocab (a windows app) goes onto the internet, accesses a dictionary web service (services.aonaware.com/DictService/), and then writes a text file with the words and defintions. Just so you know, version 1.0 of this program is complete, and works 100%.

Now I am working on version 2.0. The main difference is that in version 1, if the word was not found in the dictionary, autovocab simply made the definition of the word "word not found in dictionary". However, in this version, I am making use of a spell check web service to prompt the user with spelling suggestions if the word wasn't found in the dictionary.

The problem I am having is this. During the building process, Visual C# 2005 Express is placing an XML file, settings.xml, in the program directory. I am using this to store two user preferences. The first, the one not giving me trouble, is which dictionary autovocab is to use to define words. The second preference is the local path to a web browser. This path is used to open a web browser to display the help files. This setting isn't essential to the program, as I can do as i did in version 1.0, and use System.Diagnostics.Process.Start to open internet explorer. However, it is a feature I would like to see implemented.

I am using an openFileDialog to allow the user to select the path to the web browser. Autovocab has no problem opening and reading the settings.xml file. Also, it has no problem saving the changes to the XML file when the user only changes the dictionary they would like used. However, when the user uses the openFileDialog to select a web browser, the program looks for the settings.xml file in the folder selected in the openFileDialog, instead of in the program directory. I assumed that opening the XML file to write the changes with the line "Doc.Load("settings.xml");" would mean the file was located in the same directory as the program, but apparently not after the user uses the openFileDialog.

As far as I know, I have made no explicit link between the openFileDialog and where the program believes the current directory is. Can anyone help? Thanks.

If only computers could write programs themselves...
 
Old April 22nd, 2007, 06:35 PM
Authorized User
 
Join Date: Apr 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

BTW, one more clarification note. You may wonder why this thread is entitled "using APPLICATION CONFIGURATION FILES", when I'm asking about XML files.

When I first encountered this problem, as a beginner, I said "this must not be the proper way to store user preferences." Some quick research told me about application configuration files. However, I was told here that they are more for settings which are not changed during runtime, as is the case with autovocab.

Not sure if that helps, but hopefully everyone understands the situation a little better.

If only computers could write programs themselves...
 
Old April 23rd, 2007, 07:13 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This sounds like pretty bazaar behavior. I don't question that you are seeing it happen. Weird things happen. I would make the same assumption you are making about the behavior of the Save() method.

Is it possible you could work around this problem by starting a process on the URL or file that you want to open in the browser? If you manually do "Start->Run->'http://www.google.com'" it will start what ever your preferred browser is and load google. Perhaps you can achieve the same affect with the process start method you are already using with success. This way any URL you launch will start in the user's preferred/default browser.

-Peter
 
Old April 23rd, 2007, 08:25 PM
Authorized User
 
Join Date: Apr 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank-you so much planoie!! The line

System.Diagnostics.Process.Start("Web Address Here");

worked like a charm! I would also liked to thank-you for being such a help. You have answered a number of my questions regarding this program already!

If only computers could write programs themselves...
 
Old April 23rd, 2007, 09:39 PM
Authorized User
 
Join Date: Apr 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, so I've gotten the program completely built, and I am using the publish command to create the installation program. Everything works as expected, except for one thing, the installation does not include the settings.xml file.

You see, in the solution explorer, I right-clicked AutoVocab, clicked Add > New Item > XML file. I set the Copy To Output Directory property of the newly added file as "Copy Always". I tested it, and when I only build the project, it successfully adds the settings.xml in the program directory.

However, I am wondering how to have VC# Express do the same thing during the publish operation, so that when the program is installed on another computer, the settings.xml file is included.

If only computers could write programs themselves...
 
Old April 24th, 2007, 10:05 PM
Authorized User
 
Join Date: Apr 2006
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, here is how I solved the problem. Instead of using VC# Express' publish feature to create an installer, I used a program aptly named Install Creator. Although it cannot automatically download program dependencies (like .NET 2.0), it gave me the flexibility to include settings.xml in the program directory. Thanks everyone for their help with this whole saving preferences issue.

If only computers could write programs themselves...
 
Old April 24th, 2007, 10:27 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

While I haven't played with the installer projects much, I do believe there is a way to add whatever files you want into the install project.

One way I deal with a user settings file is to create a settings manager class that handles the loading and saving of the file. When you attempt to load a file that isn't there, a new file is created with the default settings (acquired from a new instance of the settings class). That way you don't even have to have a file to start with.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Configuration Override Files Jeff Mason Visual Studio 2005 1 March 14th, 2007 08:52 AM
Configuration files and performance ernestlambert BOOK: ASP.NET Website Programming Problem-Design-Solution 1 April 21st, 2005 11:23 AM
Configuration files hasanali00 BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 23rd, 2005 09:13 AM
Using multiple configuration files Johan VS.NET 2002/2003 0 November 10th, 2003 12:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.