Welcome to Dream.In.Code
Click Here
Getting C# Help is Easy!

Join 118,659 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 870 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



StreamWriter & xml reading problem

 
Reply to this topicStart new topic

StreamWriter & xml reading problem

Dumpen
post 2 Jul, 2008 - 12:36 PM
Post #1


New D.I.C Head

*
Joined: 21 Mar, 2008
Posts: 40

Hello.

I have this wierd problem when im writing to a text file with data from a array

I have this method:
CODE
        private void writeData()
        {
            // Open file
            StreamWriter writeData = new StreamWriter(saveMonsterSetBase.FileName, false);

            // Write all data from array to file
            for (int x = 0; x < MonsterSetBaseDataArray.Count; x++)
            {
                writeData.WriteLine(MonsterSetBaseDataArray[x]);
            }

            // Close stream
            writeData.Close();
        }


Which is trigged here:
CODE
            saveMonsterSetBase.ShowDialog();

            if (saveMonsterSetBase.FileName != "")
            {
                writeData();
            }


It works fine and opens my saveFileDialog

But after I save it I get a "file not found" on some other method I use

This is some of the method:
CODE
            // Opening txt file with location from XML
            StreamReader findMonsterStream = new StreamReader(@XMLmonsterLocation);


I get the error monster.txt (XMLmonsterLocation) is not found

It looks like the writedata changes the local path because it says

File not found in the path where I saved the file

Example:
The application and monster.txt (XMLmonsterLocation) is saved in D:\

I then use the saveFileDialog (I save a file to for example C:\) and when I access my method where I use the XMLmonsterLocation it says file not found in C:\

So I dont know why

Hope you understand

The StreamReader reads from a xml file that looks like this:
CODE
<?xml version='1.0'?>
<config>
<monsterLocation>monster.txt</monsterLocation>
<monsterSetBaseLocation>MonsterSetBase.txt</monsterSetBaseLocation>
<monsterImageLocation>mobs\</monsterImageLocation>
<mapImageLocation>maps\</mapImageLocation>
<mapInfoLocation>maps\maps.txt</mapInfoLocation>
</config>
User is offlineProfile CardPM

Go to the top of the page


allensmith
post 3 Jul, 2008 - 02:49 AM
Post #2


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 11



Thanked 3 times
My Contributions


Hello,

I have checked your code and it seems to be fine except for the fact that some of the keywords were
specific to your application so could not verify them. I am not sure, just try debugging through the
code and verify if each step is working or not.

Or if you can provide a small sample that replicates the issue, then we can have a look at it.

Regards,

Allen


This post has been edited by allensmith: 3 Jul, 2008 - 02:49 AM
User is offlineProfile CardPM

Go to the top of the page

zakary
post 3 Jul, 2008 - 04:29 AM
Post #3


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 385



Thanked 4 times

Dream Kudos: 175
My Contributions


what you should do is check if the file exist first if not then create it. Most coding standers for companies will make you do this.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/12/08 03:55AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month