FileDialog.SupportMultiDottedExtensions 属性

定义

获取或设置对话框是否支持显示和保存具有多个文件扩展名的文件。

public:
 property bool SupportMultiDottedExtensions { bool get(); void set(bool value); };
public bool SupportMultiDottedExtensions { get; set; }
member this.SupportMultiDottedExtensions : bool with get, set
Public Property SupportMultiDottedExtensions As Boolean

属性值

Boolean

如果对话框支持多个文件扩展名,则为 true;否则为 false。 默认值为 false

示例

下面的代码示例使用扩展名“.data.txt”保存文件。 此代码示例要求应用程序托管命名SaveFileDialogsaveFileDialog1Button命名button1

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestSaveFileDialog
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            button1.Click += new EventHandler(button1_Click);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "Data text files|.data.txt";
            saveFileDialog1.SupportMultiDottedExtensions = true;
            saveFileDialog1.FileOk += new CancelEventHandler(saveFileDialog1_FileOk);
            saveFileDialog1.ShowDialog();
        }

        void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            try
            {
                Stream s = saveFileDialog1.OpenFile();
                StreamWriter sw = new StreamWriter(s, Encoding.Unicode);
                sw.WriteLine("Hello, world!");
                sw.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not write file. Please try again later. Error message: " + ex.Message, "Error Writing File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
            }
        }
    }
}
Imports System.IO
Imports System.Text

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.SaveFileDialog1.SupportMultiDottedExtensions = True
        Me.SaveFileDialog1.Filter = "Data text files|*.data.txt"
        Me.SaveFileDialog1.ShowDialog()
    End Sub

    Private Sub SaveFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
        Try
            Dim MyFile As StreamWriter = New StreamWriter(Me.SaveFileDialog1.OpenFile(), Encoding.Unicode)
            MyFile.WriteLine("Hello, world!")
            MyFile.Close()
        Catch ex As Exception
            MessageBox.Show("Error: Could not write file. Please try again later. Error message: " & ex.Message, "Error Writing File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub
End Class

注解

有时,用户必须打开和使用多个文件扩展名的文件并保存。 例如,ClickOnce部署技术使用的应用程序清单文件以复杂的文件扩展名“.exe.manifest”结尾。 将此属性设置为 true 允许将 Filter 属性设置为多点扩展。

false如果是SupportMultiDottedExtensions,并且你向Filter派生控件分配了多点扩展,例如SaveFileDialog将只使用字符串中的最后一个扩展。 例如,将使用“.manifest”而不是“.exe.manifest”。

适用于

另请参阅