Scintillanet, how to save its text to a file?

时间:2016-04-21 22:15:50

标签: c# .net textbox savefiledialog scintilla

I am programming a code editor in C# using visual studio and I use scintillaNET as the text editor in my program, now I want the user to be able to save the text from the editor to a file. If I used RichTextBox, the code for saving the file would have been:

richTextBox.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichText);

Now I tried it for my scintilla editor:

scintilla.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichText);

but I got error: ScintillaNet.Scintilla does not contain a definition for SaveFile and no extension method SaveFile"...

What's the appropriate code/method for saving text from Scintilla editor to a file. Can someone tell me? Thank you

2 个答案:

答案 0 :(得分:0)

我试图用ScintillaNET做同样的事情,并且找到了一种方法。

public void SaveToFile(string filename)
{
     File.WriteAllText(filename,"");
     using(StreamWriter strwriter = System.IO.File.AppendText(filename))
     {
         strwriter.Write(this.TextArea.Text);
     }
}

答案 1 :(得分:0)

ScintillaNet控件没有一种“ 保存文本内容到文件”的方法...

相反,您必须使用以下属性获取文本内容:

ScintillaNET.Scintilla.Text

然后,您可以使用.NET System.IO.File.WriteAllText()方法或等效方法将其保存到磁盘文件:

System.IO.File.WriteAllText(@"c:\path\filename.txt", YourScintillaControlName.Text);