Output from gump to file

Karmageddon

Active Member
May 24, 2017
30
0
48
What I want to do is be able to take text entries from a gump and output it into a text file on the server. Is this possible and what would I use to do it?
 

Feeh

Well-Known Member
Apr 1, 2014
63
10
31
Try this
Code:
using System.IO;
...
		public override void OnResponse( Server.Network.NetState sender, RelayInfo info )
		{
			using (TextWriter tw = File.CreateText(Path.Combine(Environment.CurrentDirectory, "THE_TEXTFILE_NAME.txt")))
			{
				tw.WriteLine($"The player {sender.Mobile.Name} sent this:");
				tw.WriteLine(info.TextEntries[0].Text);
			}
 
  • Like
Reactions: Lokai

Karmageddon

Active Member
May 24, 2017
30
0
48
Thank you
[doublepost=1552860999][/doublepost]Well got a chance to try it. Everything compiles but am not getting any file output. This is the code I have atm:
Code:
public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
        {
            Mobile from = sender.Mobile;

            switch(info.ButtonID)
            {
                case 0:
                {
                    break;
                }
                case 1:
                {
                    using (TextWriter tw = File.CreateText(Path.Combine(Environment.CurrentDirectory, "Staff_Rating.txt")))
                    {
                        tw.WriteLine("The player {sender.Mobile.Name} sent this:");
                        tw.WriteLine(info.TextEntries[2].Text);
                        tw.WriteLine(info.TextEntries[3].Text);
                        tw.WriteLine(info.TextEntries[4].Text);

                        break;
                    }
                }

            }
        }
 

Vorspire

Vita-Nex: Core
Admin
ServUO Developer
Jul 29, 2013
1,093
203
32
United Kingdom
core.vita-nex.com
Shard Name
Ultima Shards: Multiverse
Donate
Donate money to this user
Code:
tw.WriteLine("The player {sender.Mobile.Name} sent this:");
-->

Code:
tw.WriteLine($"The player {sender.Mobile.Name} sent this:");
<-->

Code:
tw.WriteLine("The player " + sender.Mobile.Name + " sent this:");
 

Karmageddon

Active Member
May 24, 2017
30
0
48
A little more help if anyone can. I have the whole thing working, but it is not working exactly the way I want it to be. I want to work like command logs are created, where the log is the same file but continues to add to it. This is the code I currently have.
Code:
case 1:
                {
                        if (!Directory.Exists("Logs"))
                            Directory.CreateDirectory("Logs");

                        var directory = Path.Combine("Logs", "Rating");

                        if (!Directory.Exists(directory))
                            Directory.CreateDirectory(directory);
                        try
                        {
                            using (TextWriter tw = File.CreateText(Path.Combine(directory, "" + info.TextEntries[1].Text + "_Rating.txt")))
                            {
                                tw.Flush();                           
                                tw.WriteLine("The player " + sender.Mobile.Name + " sent this rating");
                                tw.WriteLine("Staff Member:" + info.TextEntries[1].Text + " ");
                                tw.WriteLine("Rating:" + info.TextEntries[2].Text + " ");
                                tw.WriteLine("Comments:" + info.TextEntries[3].Text + " ");
                              
                            }
                        }
                        catch
                        {
                        }
                    break;
                }
 

Karmageddon

Active Member
May 24, 2017
30
0
48
The File.OpenWrite(String) was actually wrong. But, I did find what I needed from the link you posted.
It should File.AppendText(String)

Thank you for the assistance
 

PyrO

Well-Known Member
Jan 27, 2015
1,074
76
Yes you are right, by default the OpenWrite doesnt append, it would still override it, AppendText is fine there :)