Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.0 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 November 12th, 2008, 03:52 AM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default Need Help with the Application.config file

Hi

I am making an application.config file that will hold a path to a file that I save a private key into.

I need this path to be relative but every time I make a relative path it starts me in the bin directory. I need to start outside of this directory.

Like here is the path to the file

I:\Comp7615_Assignment3\App_Code\Assignment3\priva teKey.config

I get this instead

I:\Comp7615_Assignment3\bin\Debug\App_Code\Assignm ent3\privateKey.config

So how can i get it to like about.

I can do it through c# by finding doing something like this:

 DirectoryInfo parentDirectory = Directory.GetParent(Directory.GetParent(Applicatio n.StartupPath).ToString());
 string documentationPath = parentDirectory.ToString() + @"\Documentation\Source Code Documentation.chm";

but I don't know how to do something like that in an application.config file

this is what I have in my file so


Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key='keyPath' value='./App_Code/Assignment3/privateKey.config'/>        
    </appSettings>
</configuration>
 
Old November 12th, 2008, 05:07 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The relative directory will be relative to wherever the executable is running, which if you are running inside Visual Studio will be the bin\Debug directory.

You have to think about when you deploy this application, what the final layout of these files is going to be.

If you never plan to deploy this, then why not just put the absolute path in the application.config file, or simply write "../../App_Code/Assignment3/privateKey.config"

/- Sam Judson : Wrox Technical Editor -/
 
Old November 12th, 2008, 04:04 PM
Friend of Wrox
 
Join Date: Sep 2007
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
quote:Originally posted by samjudson
 The relative directory will be relative to wherever the executable is running, which if you are running inside Visual Studio will be the bin\Debug directory.

You have to think about when you deploy this application, what the final layout of these files is going to be.

If you never plan to deploy this, then why not just put the absolute path in the application.config file, or simply write "../../App_Code/Assignment3/privateKey.config"

/- Sam Judson : Wrox Technical Editor -/
Hi can you tell me more about what you mean by final layout so I know for future knowledge. Like where would it the default file be if you made it into an msi file and installed on the computer?

For this application I never plan to deploy it but it needs to be relative since this is an assignment for school. I can't my teacher to have to change the path every time he uses my program to mark it. Plus since it is a chat program and will be deployed on at least 2 computers he would already have to change it twice.

I tried your code it seems to work can you tell me more how that works.

like I forgot what those 2 dots do and where this path is starting. Is it going up 2 directories then starting at the parent directory and working it's way down?

 
Old November 13th, 2008, 06:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I answered one of those already:

Quote:
quote:The relative directory will be relative to wherever the executable is running, which if you are running inside Visual Studio will be the bin\Debug directory.
You've answered the other yourself.

/- Sam Judson : Wrox Technical Editor -/
 
Old November 13th, 2008, 07:47 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think a better solution is to set the key file to be copied to the output directory. Set that in the file properties toolbox. then the file will be copied to wherever the compilation output goes (i.e. bin\Debug or bin\Release, etc.). then you simply can reference the file in the runtime directory and it will always be there.

-Peter
compiledthoughts.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
application config ms_kout ASP.NET 2.0 Professional 2 May 23rd, 2007 01:21 PM
Defining Application Root in web.config wdwright ASP.NET 2.0 Basics 0 August 22nd, 2006 04:27 AM
Machine.config and data application block beachboy1976 ASP.NET 1.0 and 1.1 Professional 0 August 9th, 2006 03:01 PM
C# Config File BasilFawlty C# 8 January 17th, 2005 12:26 PM
what's wrong with my web application or config junhuanzheng Servlets 2 March 11th, 2004 04:47 AM





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