Click here to Skip to main content
16,005,734 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Raising Events. Pin
Robert Rohde22-Dec-05 10:02
Robert Rohde22-Dec-05 10:02 
GeneralRe: Raising Events. Pin
HakunaMatada22-Dec-05 17:14
HakunaMatada22-Dec-05 17:14 
QuestionImport yahoo address book in .net application Pin
ashishnagar122-Dec-05 0:11
ashishnagar122-Dec-05 0:11 
AnswerRe: Import yahoo address book in .net application Pin
Colin Angus Mackay22-Dec-05 22:20
Colin Angus Mackay22-Dec-05 22:20 
AnswerRe: Import yahoo address book in .net application Pin
Dave Kreskowiak23-Dec-05 5:49
mveDave Kreskowiak23-Dec-05 5:49 
QuestionConfiguration combobox missing on the standard toolbar in whidbey beta Pin
hiraljv21-Dec-05 20:14
hiraljv21-Dec-05 20:14 
QuestionPath to default files called by program Pin
smurfy3421-Dec-05 11:14
smurfy3421-Dec-05 11:14 
AnswerRe: Path to default files called by program Pin
Dave Kreskowiak21-Dec-05 13:13
mveDave Kreskowiak21-Dec-05 13:13 
smurfy34 wrote:
what path do I hardcode


:SMACK: Stop right there! You don't hardcode paths into your code, ever! This is because sometimes people don't have their Program Files folder on the C: drive, or someone might not install your app in the folder you think they will.

Two rules: Don't ever hardcode paths. never assume that the current directory is what you think it is. And always use comlete, full qualified paths when specifying a file to work with.

You'll save yourself many a headache trying to troubleshoot a problem on a customers machine when you can't replicate the problem on your test machine.

So, if I can't hardcode a path, how can I possibly build a fully qualified filepath?

Easy. If you put the configuration file in the same folder as the .EXE, you can use <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassstartuppathtopic.asp" rel="nofollow">Application.StartupPath</a>[<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassstartuppathtopic.asp" target="_blank" rel="nofollow" title="New Window">^</a>] to get the path to the folder that the .EXE is in, then just use <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiopathclasscombinetopic.asp" rel="nofollow">Path.Combine</a>[<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiopathclasscombinetopic.asp" target="_blank" rel="nofollow" title="New Window">^</a>] to combine the StartupPath with the filename of your config file to get the complete path to the file.
string configFilePath = Path.Combine( Application.StartupPath, @"config.filename" );



RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

AnswerRe: Path to default files called by program Pin
HakunaMatada22-Dec-05 0:07
HakunaMatada22-Dec-05 0:07 
GeneralRe: Path to default files called by program Pin
Dave Kreskowiak22-Dec-05 5:52
mveDave Kreskowiak22-Dec-05 5:52 
GeneralRe: Path to default files called by program Pin
HakunaMatada22-Dec-05 17:12
HakunaMatada22-Dec-05 17:12 
GeneralRe: Path to default files called by program Pin
Dave Kreskowiak22-Dec-05 17:55
mveDave Kreskowiak22-Dec-05 17:55 
GeneralRe: Path to default files called by program Pin
HakunaMatada22-Dec-05 18:17
HakunaMatada22-Dec-05 18:17 
AnswerRe: Path to default files called by program Pin
HakunaMatada22-Dec-05 0:11
HakunaMatada22-Dec-05 0:11 
Questionerror LNK2028: unresolved token Pin
Lythimer21-Dec-05 2:41
Lythimer21-Dec-05 2:41 
AnswerRe: error LNK2028: unresolved token Pin
hiraljv21-Dec-05 20:21
hiraljv21-Dec-05 20:21 
GeneralRe: error LNK2028: unresolved token Pin
Lythimer22-Dec-05 9:12
Lythimer22-Dec-05 9:12 
QuestionPictureBox in .NET Pin
HakunaMatada20-Dec-05 18:17
HakunaMatada20-Dec-05 18:17 
AnswerRe: PictureBox in .NET Pin
Dave Kreskowiak21-Dec-05 2:48
mveDave Kreskowiak21-Dec-05 2:48 
GeneralRe: PictureBox in .NET Pin
HakunaMatada22-Dec-05 0:23
HakunaMatada22-Dec-05 0:23 
GeneralRe: PictureBox in .NET Pin
Dave Kreskowiak22-Dec-05 1:39
mveDave Kreskowiak22-Dec-05 1:39 
GeneralRe: PictureBox in .NET Pin
HakunaMatada22-Dec-05 20:26
HakunaMatada22-Dec-05 20:26 
GeneralRe: PictureBox in .NET Pin
Dave Kreskowiak23-Dec-05 3:57
mveDave Kreskowiak23-Dec-05 3:57 
GeneralRe: PictureBox in .NET Pin
HakunaMatada23-Dec-05 17:27
HakunaMatada23-Dec-05 17:27 
GeneralRe: PictureBox in .NET Pin
Dave Kreskowiak26-Dec-05 6:15
mveDave Kreskowiak26-Dec-05 6:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.