Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hy,

I have a bunch of icons from which the player can choose as his own Icon. I want to retrive the user icon path togheter with is user name to write it in a file but it seems my program dosent wnat to do that. It writes and also rewrites player name (wrong not in a new line) and not the path of the icon (the location is in my computer). Bellow the code ...

Sincerly,

C#
private void Add_Click(object sender, EventArgs e)
       {
           string myInputDate = " ";

           //foreach (Player name in Name)
           //{
           String playerN = nameBox.Text;
           String pathN = System.IO.Path.GetDirectoryName(pictBox.ImageLocation);
           Player player = new Player(playerN,pathN);
               myInputDate += player.Name + "," + player.Path + "\n";
         //  }

           File.WriteAllText(@"C:\Users\Marius\Desktop\GameMachineWF\GameMachineWF\Player.csv", myInputDate);
       }
Posted
Comments
[no name] 29-Mar-14 16:14pm    
Well that is what you told it to do. You are just writing over the same file over and over did you really mean to Append instead? As for the icon path, we would have no idea what player.Path actually is. You need to debug your code and find out what is happening to that string. And creating your Player object only to throw it away seems to me to be a pretty useless operation. Why are you not saving playerN and pathN?

1 solution

Path is the link of the file:
C#
<pre lang="c#">
private void Add_Click(object sender, EventArgs e)
        {
  
            int wins =0;
            int score =0;
            int plays =0;
            player = new Player(nameBox.Text, currentImage,score, wins,plays);
            player.Write();
            
        }

And the write method
C#
public void Write ()
       {
           StreamWriter sw = File.AppendText(@".\Player.csv");
           string line = this.Name + "," + this.Paths + "," + this.Score + "," + this.wins + "," + this.level + "," + this.plays;
           sw.WriteLine(line);
           sw.Close();

       }

And Add Player method with currentImage parameter

C#
private void AddPlayer_Load(object sender, EventArgs e)
      {


          System.IO.DirectoryInfo director = new System.IO.DirectoryInfo(@".\imagini\");
          try
          {
              if ((director.Exists))
              {
                  System.IO.FileInfo file = null;

                  foreach ( System.IO.FileInfo eachfile in director.GetFiles())

                  {
                      file = eachfile;
                      if (file.Extension == ".jpg")
                      {
                          lista.Add(file.FullName);
                          imageLen++;
                      }

                  }

                  pictBox.Image = Image.FromFile(lista[0].ToString());
                  currentImage = lista[0].ToString();
                  i = 0;

              }
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900