Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 17th, 2006, 03:23 PM
Authorized User
Join Date: Nov 2003
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to load an xml file that is in same project?

Hey guys, I am new to winforms so please forgive me.
I am trying to write to an xml file that I created. The file is in the same project (in the root level of the project, not hidden away in sub folders).

However, it bombs out when it tries to find the xml file:

Here's the error:
{System.IO.FileNotFoundException: Could not find file 'S:\source\cs\sTopGun\CSharp\sBriefcase\BriefcaseS yncNotifier\bin\Debug\SyncSettings.xml

Here's my code so far:

                DataSet xmlDataSet = new DataSet();
                StreamReader myStreamReader = new StreamReader("SyncSettings.xml");
I tried using StreamReader myStreamReader = new StreamReader(Application.StartupPath + "\\SyncSettings.xml");

but that didn't work either.

I checked and Application.StartupPath is returning the following:

S:\source\cs\sTopGun\CSharp\sBriefcase\BriefcaseSy ncNotifier\bin\Debug
It's going all the way to the Debug directory. I just need it to point to the following:

S:\source\cs\sTopGun\CSharp\sBriefcase\BriefcaseSy ncNotifier
Any ideas? Thanks!!!

  #2 (permalink)  
Old November 28th, 2006, 02:50 PM
Authorized User
Join Date: Sep 2003
Location: Park City, UT, .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts


Not the most graceful solution, but here are two ways to accomplish this:

      string folder = Application.StartupPath;

      if (folder.ToLower().EndsWith(@"\debug"))
        folder = folder.Substring(0, folder.Length - @"\Debug".Length);

      if (folder.ToLower().EndsWith(@"\bin"))
        folder = folder.Substring(0, folder.Length - @"\bin".Length);

      string filepath = Path.Combine(folder, "SyncSettings.xml");


      string anotherfilepath = Path.Combine(Application.StartupPath, @"..\..\SyncSettings.xml");


- Roger Nedel

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access is denied" load a simple xml file nana XML 12 May 12th, 2010 07:01 AM
Can not load XML kolucoms XML 50 May 28th, 2008 05:25 AM
Parse/Load/Search xml file size near about 1 GB sandeep_akhare XML 4 September 19th, 2006 04:47 AM
Getting VB.NET to load & update XML file kyma XML 0 March 19th, 2005 04:58 PM
LOAD A XML FILE FROM JAVASCRIPT nen Javascript How-To 1 December 20th, 2004 11:03 AM

All times are GMT -4. The time now is 06:19 AM.

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