c# - 默认文件名 SaveFileDialog

标签 c# .net savefiledialog

我想用 默认文件名 从值 DataGridViewCells 创建 SaveFileDialog

到目前为止我已经尝试过了

private void buttonSave_Click(object sender, EventArgs e) 
{
    //first
    //mySaveFileDialog.FileName = myDataGridView.SelectedCells[2].Value.ToString();
    //second
    SaveFileDialog saveFile = new SaveFileDialog();
    saveFile.FileName = myDataGridView.SelectedCells[2].Value.ToString();
    saveFile.ShowDialog();
}

谁能帮我解决这个问题?

最佳答案

SaveFileDialog 有一个用于此目的的属性:DefaultFileName使用 Silverlight 或 FileName使用.NET

问题中的(不可编译的)代码将变为:

    private void buttonSave_Click(object sender, EventArgs e) 
    {
        SaveFileDialog mySaveFileDialog = new SaveFileDialog();
        //Silverlight
        mySaveFileDialog.DefaultFileName = myDataGridView.SelectedCells[2].Value.ToString();
        //.NET
        mySaveFileDialog.FileName = myDataGridView.SelectedCells[2].Value.ToString();
    }

关于c# - 默认文件名 SaveFileDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21199558/

相关文章:

c# - 使用数组作为 string.Format() 的参数

c# - 将 Dapper 与 '?' 一起使用

wpf - 有没有人注意到,当双击选择一个文件时,WPF 文件对话框会将点击传递到 UI?

c# - 即使在导入 Win32 命名空间后,SaveFileDialog 在 UWP 中也不起作用

javascript - 如何将签名保存到本地驱动器

c# - 如何延长 Rx.NET 中 Observable Timer 的持续时间?

c# - 路由声明它在 system.web 中定义但未找到错误

c# - AutoMapper - 如何根据类名映射到属性名?

c# - 发现 op_Addition 或实现 Expression.Add 的方法

javascript - Window.open 弹出窗口卡住整个桌面