如何从TCP客户端生成消息保存在excel或TEXT文件exe应用程序中 [英] How to do I generate messages from TCP client is saved in excel or TEXT file exe application

查看:147
本文介绍了如何从TCP客户端生成消息保存在excel或TEXT文件exe应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为TCP侦听器编写此代码,获取消息将以文本形式存储为日志文件

它在Visual Studio开发中工作但我发布的文件不会被创建或者没有存储来自客户端的消息< br $>


I write this code for TCP listener that get message will be stored in text as log file
it working in Visual Studio development but I publish no file will be created or not stored messages from client

void server_DataReceived(object sender, SimpleTCP.Message e)
        {
            try
            {
                txtStatus.Invoke((MethodInvoker)delegate()
                {
                    
                    e.ReplyLine(string.Format("\r\n CLIENT:>>{0}\r\n", e.MessageString));
                    CommonControls.writeToLogFile(string.Format("{0}\r\n", e.MessageString));
                });
            }
            


            catch (SocketException e1)
            {
                output = "SocketException: " + e1.ToString();
               

            }
        }







和写入文本文件




and the write in text file

public static void writeToLogFile(string logMessage)
        {
            string strLogMessage = string.Empty;

            string strLogFile = System.Configuration.ConfigurationSettings.AppSettings["logFilePath"].ToString();
            StreamWriter swLog;

            strLogMessage = string.Format("{0}: {1}", DateTime.Now, logMessage);

            if (!File.Exists(strLogFile))
            {
                swLog = new StreamWriter(strLogFile);
            }
            else
            {
                swLog = File.AppendText(strLogFile);
            }

            swLog.WriteLine(strLogMessage);
            swLog.WriteLine();

            swLog.Close();

        }

以及我需要如何在已发布的exe文件中的excel文件中写入消息



我尝试过:



i在C#Visual Studio中通过保存日志文件在BIN文件夹中尝试但在发布EXE文件时如何获取



提前致谢

as well as i need how to write messages in excel file in published exe file

What I have tried:

i tried in C# Visual Studio by saving logfile when it is BIN folder but how to get when it is Publish EXE file

Thanks in advance

推荐答案

参见我应该在哪里存储我的数据? [ ^ ]获取有关存储应用程序生成数据的最佳位置的指导。



关于如何在已发布的exe文件中的excel文件中写入消息的问题。您需要提供正确的解释,说明您要执行的操作。 Excel数据与简单文本完全不同。
See Where should I store my data?[^] for guidance on the best places to store application generated data.

As to the question "how to write messages in excel file in published exe file". You need to provide a proper explanation of what you are trying to do. Excel data is completely different from simple text.


这篇关于如何从TCP客户端生成消息保存在excel或TEXT文件exe应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆