Esporta (0) Stampa
Espandi tutto
EN
Il contenuto non è disponibile nella lingua di destinazione, ma solo in inglese.

RichTextBox.SaveFile Method

Saves the contents of the RichTextBox to a file.

Overload List

Saves the contents of the RichTextBox to a Rich Text Format (RTF) file.

[Visual Basic] Overloads Public Sub SaveFile(String)
[C#] public void SaveFile(string);
[C++] public: void SaveFile(String*);
[JScript] public function SaveFile(String);

Saves the contents of a RichTextBox control to an open data stream.

[Visual Basic] Overloads Public Sub SaveFile(Stream, RichTextBoxStreamType)
[C#] public void SaveFile(Stream, RichTextBoxStreamType);
[C++] public: void SaveFile(Stream*, RichTextBoxStreamType);
[JScript] public function SaveFile(Stream, RichTextBoxStreamType);

Saves the contents of the RichTextBox to a specific type of file.

[Visual Basic] Overloads Public Sub SaveFile(String, RichTextBoxStreamType)
[C#] public void SaveFile(string, RichTextBoxStreamType);
[C++] public: void SaveFile(String*, RichTextBoxStreamType);
[JScript] public function SaveFile(String, RichTextBoxStreamType);

Example

[Visual Basic, C#, C++] The following example saves the contents of the RichTextBox into an ASCII text file. The example uses the SaveFileDialog class to display a dialog to request the path and file name from the user. The code then saves the contents of the control to that file. The example uses this version of the SaveFile method to specify that the file be saved as an ASCII text file instead of the standard Rich Text Format. This example assumes that the code is placed in a Form class that has a RichTextBox control named richTextBox1.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of SaveFile. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub SaveMyFile()
    ' Create a SaveFileDialog to request a path and file name to save to.
    Dim saveFile1 As New SaveFileDialog()
    
    ' Initialize the SaveFileDialog to specify the RTF extension for the file.
    saveFile1.DefaultExt = "*.rtf"
    saveFile1.Filter = "RTF Files|*.rtf"
    
    ' Determine if the user selected a file name from the saveFileDialog.
    If (saveFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
        And (saveFile1.FileName.Length) > 0 Then
    
        ' Save the contents of the RichTextBox into the file.
        richTextBox1.SaveFile(saveFile1.FileName, _
            RichTextBoxStreamType.PlainText)
    End If
End Sub


[C#] 
public void SaveMyFile()
{
   // Create a SaveFileDialog to request a path and file name to save to.
   SaveFileDialog saveFile1 = new SaveFileDialog();

   // Initialize the SaveFileDialog to specify the RTF extension for the file.
   saveFile1.DefaultExt = "*.rtf";
   saveFile1.Filter = "RTF Files|*.rtf";

   // Determine if the user selected a file name from the saveFileDialog.
   if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
      saveFile1.FileName.Length > 0) 
   {
      // Save the contents of the RichTextBox into the file.
      richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText);
   }
}


[C++] 
public:
void SaveMyFile()
{
   // Create a SaveFileDialog to request a path and file name to save to.
   SaveFileDialog* saveFile1 = new SaveFileDialog();

   // Initialize the SaveFileDialog to specify the RTF extension for the file.
   saveFile1->DefaultExt = S"*.rtf";
   saveFile1->Filter = S"RTF Files|*.rtf";

   // Determine if the user selected a file name from the saveFileDialog.
   if(saveFile1->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
      saveFile1->FileName->Length > 0) 
   {
      // Save the contents of the RichTextBox into the file.
      richTextBox1->SaveFile(saveFile1->FileName, RichTextBoxStreamType::PlainText);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

RichTextBox Class | RichTextBox Members | System.Windows.Forms Namespace

Microsoft sta conducendo un sondaggio in linea per comprendere l'opinione degli utenti in merito al sito Web di MSDN. Se si sceglie di partecipare, quando si lascia il sito Web di MSDN verrà visualizzato il sondaggio in linea.

Si desidera partecipare?
Mostra:
© 2014 Microsoft