如何在我的项目中使用notepad ++

时间:2015-02-26 12:00:26

标签: c# php notepad++

我有一些保存在数据库中的PHP代码。 我想编写一个程序,从数据库中读取php,然后加载到notepad ++中,然后编辑保存到数据库。

可以在我们的php项目中使用notepad ++作为编辑器吗?

或者可以将notepad ++加载到我们的c#项目中并用作编辑器吗?

问题: 如何将notepad ++加载到(c#或php)项目作为编辑器?

2 个答案:

答案 0 :(得分:1)

我理解你的问题(也许是错的) 1.在程序中,单击文件时,使用此命令调用notepad ++

<Path to your notepad++> -n<line>  <Path to your source code file>
  1. 使用此类FileSystemWatcher https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx
  2. 检测更改或文件

答案 1 :(得分:1)

在C#中,您可以先将PHP代码保存到C:\ temp \(或您指定的某个地方)的临时文件中

然后

System.Diagnostics.Process.Start(@"C:\Program Files\Notepad++\notepad++.exe", @"C:\temp\tmpfile.php");

(我猜测文件路径名称,根据需要进行更改)

然后正如VõQuangHòa所说,使用FileSystemWatcher类来监视要保存的文件,当它出现时,程序将读取它并将其保存回数据库。

FileSystemWatcher fsw = new FileSystemWatcher(@"C:\temp\");
fsw.Filter = "tmpfile.php";
fsw.NotifyFilter = NotifyFilters.LastWrite;
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
fsw.EnableRaisingEvents = true;

并添加功能

private static void fsw_Changed(object sender, FileSystemEventArgs e) 
{
   // Code to save file to DB and delete temp file.
}
相关问题