编辑服务器上的文本文件 [英] Edit a text file on server

查看:133
本文介绍了编辑服务器上的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的服务器上有一个文本文件。



例如Www.MySite.Com/File.txt



所以,我怎么编辑这个文件像:System.IO.WriteLine()。



提前谢谢,,,

-------------------- -----------------

我想每年不用远程sql编写我的软件日志...我有一个Cpanel服务器.. ..

解决方案

只需创建一个简单的基于Web的服务,该服务接受您要记录的参数,并将其写入文件中。但我建议你也添加一些身份验证。但是,您将无法使用客户端的简单文件IO,例如,您必须使用WebRequest。但是你也可以使用NLog的NetworkTarget。我会考虑这个,因为它会让你重新考虑你的日志记录策略。


假设你在后端使用ASP.Net和C#。

你可以使用StreamWriter在File.txt中添加更多行,如...



 使用 System.IO; 

...
StreamWriter sw = new StreamWriter( @ C:\ MyFilePath \ MyFile.txt true );
// true至关重要,否则它将从零开始运行。
// true表示它应附加新文本。
< span class =code-comment> // 您可能需要做一些wxtra工作才能获得正确的文件路径,因为您可能
// 使用ASP.Net
// usualy,MyFile.txt将写入.aspx文件所在文件夹中的文件

sw.WriteLine( 我的消息1);
sw.WriteLine( 我的留言2);


Hi ,
I have a text file in my server .

e.g Www.MySite.Com/File.txt

so , how can i edit this file Like : System.IO.WriteLine() .

Thank in advance ,,,
-------------------------------------
I want to write a log of my Software every year without using remote sql ... I have a Cpanel server ....

解决方案

Simply create a simple web based service, that accepts the parameters you want to log, and write them in the file. But I suggest you to add some sort of authentication too. But you won't be able to use simple file IO from your client, you have to use WebRequest for example. But you could use NLog's NetworkTarget also. I would consider this, since it will let you reconsider your logging strategy over time.


Assuming you are using ASP.Net and C# in the backend.
You can add more lines to what is already written in File.txt using StreamWriter as in...

using System.IO;

...
StreamWriter sw = new StreamWriter(@"C:\MyFilePath\MyFile.txt", true);
//"true" is crucial, because otherwise it will start the file from zero.
//"true" indicates that it should append new text.
//you may need to do some wxtra work to get the right path to your file since your likely 
//using ASP.Net
//usualy, "MyFile.txt" will write to a file in the same folder that your .aspx file is

sw.WriteLine("My message 1");
sw.WriteLine("My message 2");


这篇关于编辑服务器上的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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