Preselection in the save dialog (c#)
Posted
by
FullmetalBoy
on Stack Overflow
See other posts from Stack Overflow
or by FullmetalBoy
Published on 2011-02-19T14:31:09Z
Indexed on
2011/02/19
23:25 UTC
Read the original article
Hit count: 228
Goal:
Save a notepad file in the computer. (C#)
Problem:
I don't know how to make a preselection as "TXT Files(*.txt)" in the "Save as type:" when save dialog display?
// Fullmetalboy
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Labb2_application
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void mnuFileOpen_Click(object sender, EventArgs e)
{
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Öppna";
fDialog.Filter = "Text files|*.txt";
fDialog.InitialDirectory = @"C:\Windows";
fDialog.ShowHelp = true;
DialogResult result = fDialog.ShowDialog(); // Show the dialog and get result.
if (result == DialogResult.OK)
{
string fileAdress = fDialog.FileName;
try
{
string textContent = File.ReadAllText(fileAdress);
rtxtDisplay.Text = textContent;
}
catch (IOException)
{
}
} // If syntax
}
private void mnuFileSave_Click(object sender, EventArgs e)
{
saveAsFileDialog.ShowDialog();
}
private void mnuFileSaveAs_Click(object sender, EventArgs e)
{
saveAsFileDialog.Filter = "Text files|*.txt";
saveAsFileDialog.ShowDialog();
}
private void mnuFileExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void saveAsFileDialog_FileOk(object sender, CancelEventArgs e)
{
string fileNameAddress = saveAsFileDialog.FileName;
File.WriteAllText(fileNameAddress, rtxtDisplay.Text);
}
} // Partial Class
}
© Stack Overflow or respective owner