如何在记事本中打开文件进行编辑 [英] How to open a file in notepad for editing

查看:295
本文介绍了如何在记事本中打开文件进行编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我一直在开发一个网站,要求在记事本中打开.txt,.xml,.config文件,在这里我可以对其进行编辑并保存在其原始位置.
我已经尝试过

System.Diagnostics.Process.Start("notepad.exe", "Filepath");

但是部署项目时,相同的代码无法打开文件进行编辑.
请提出解决我问题的方法.
在此先感谢
Amit

Hi all,
I have been developing a website where the requirement is to open .txt, .xml, .config files in notepad where I can edit the same and save at its original position.
I have tried with

System.Diagnostics.Process.Start("notepad.exe", "Filepath");

but when the project is deployed the same code is unable to open the file for editting purpose.
Please suggest a solution to my problem.
Thanks in advance
Amit

推荐答案

这很简单.

客户端:运行javascript,通过浏览器显示HTML.

服务器:运行C#,将HTML发送到客户端.

在服务器上执行Process.Start时,它将在服务器上执行.这就是记事本将打开的地方.这可能是您的Web服务器管理人员正向您发誓的地方...

它可以在部署之前在PC上运行,因为客户端和服务器是同一台计算机,并且您没有注意到.
It''s quite simple.

Client: runs javascript, shows HTML via browser.

Server: runs C#, sends HTML to client.

When you execute Process.Start on the server, it executes on the server. And that is where Notepad will open. And that is probably where your web server administration person is busy swearing at you...

It worked on your PC prior to deployment because the client and server were the same machine, and you didn''t notice.


如果您正在开发网站,则无法访问notepade.exe.文件,因为它有安全隐患,但是有很多方法可以解决此问题,但这是一个不好的做法.

您应该做的是将要编辑的文件上传到服务器,然后在网页中打开它,然后允许用户进行更改,然后让用户将文件下载到他们的计算机上.

请注意,如果要将txt,xml文件加载到浏览器中,则需要检查CSS(跨站点脚本)黑客和其他错误的文本".

希望有帮助.
关于
If you are developing a website you cannot access the notepade.exe file as it is a security risk, well there are ways of getting around this, but this is a bad practice.

What you should rather do is upload the file you want to edit to the server, then open it within the webpage, and then allow the user to make changes and then let the user download the file to thier computer.

Please note that if you are going to load the txt, xml file to the browers you will need to check for CSS (Cross site scripting) hacks and other bad "text".

Hope this help.
Regards


尝试的想法(直觉认为如果这是一个您所说的网站,问题就出在1中.):

1.您说这是一个网站-运行客户端或服务器端的代码是否有问题?文件存储在客户端还是服务器上?要在客户端还是服务器上查看?使用ASP.NET?如果是客户端,您在客户端上运行了什么.NET代码?如果是服务器端,您在IIS中吗?如果是这样,用户如何与打开文件的服务器端进行交互? IIS是否甚至具有与服务器桌面进行交互的权限?您暗示在开发环境中一切正常,但是如果客户端和服务器实际上是同一台机器,这是否可以隐藏真正的问题?您是否依赖Notepad能够使用HTTP在Web上打开文件?如果客户端计算机根本没有运行Windows,该怎么办?如果有任何问题,您可能不得不放弃记事本,而选择带有Form/Textarea的网页.

2.在该行代码中放入try/catch块并记录所有异常的日志-至少它可以为您提供失败的线索.

3.检查明显的地方-记事本实际上已安装在相关计算机上(启动/运行/记事本能正常工作吗?).

4.这是代码许可问题吗?代码是否具有/需要完全信任"(或完全信任)?

5.用户(或正在运行代码的服务器帐户)是否具有要尝试打开的文件的文件(或HTTP)访问权限?
Ideas to try (with a gut feel that if this is a web site as you say, the problem is somewhere in 1.):

1. You say this is a web site - is your problem with code running client side or server side? Is the file stored on the client or the server? To be viewed on the client or the server? Using ASP.NET? If client side, what .NET code do you have running on the client? If server side, are you in IIS? If so, how does the user interact with a file opened server side? Does IIS even have permission to interact with the server desktop? You imply things work when you are in your development environment - but could this be hiding the real problem if client and server are then actually the same machine? Are you relying on Notepad being able to open a file over the web using HTTP? And what if the client computer isn''t running Windows at all? If any of this is the issue, you might have to abandon Notepad and go for something like a web page with a Form / Textarea.

2. Put try / catch block and some logging of any exception round that line of code - at least it might give you a clue you what''s failing.

3. Check the obvious - Notepad is actually installed on the relevant computer (Start / Run / Notepad works?).

4. Is this a code permission issue? Does the code have / need Full Trust (or more trust than it has)?

5. Does the user (or server account the code is running in) have file (or HTTP) access permissions for the file you are trying to open?


这篇关于如何在记事本中打开文件进行编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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