C# 開檔對話盒(OpenFileDialog) / 存檔對話盒(SaveFileDialog)
C# 開檔對話盒(OpenFileDialog) / 存檔對話盒(SaveFileDialog)
開檔對話盒:
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = “SYWEB_Backup|*.bak”;
openFileDialog1.Title = “Open an Backup”;
openFileDialog1.RestoreDirectory = true ;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StrPath = openFileDialog1.FileName.ToString();
}
存檔對話盒
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = “Backup|*.bak”;
saveFileDialog1.Title = “Save an Backup”;
String StrName = String.Format(“Backup_{0}_{1}”, m_ver, DateTime.Now.ToString(“yyyyMMdd”));
saveFileDialog1.FileName = StrName; // Default file name
saveFileDialog1.DefaultExt = “.bak”; // Default file extension
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
StrPath=saveFileDialog1.FileName.ToString();
}
One thought on “C# 開檔對話盒(OpenFileDialog) / 存檔對話盒(SaveFileDialog)”
開檔對話盒(OPENFILEDIALOG) / 存檔對話盒(SAVEFILEDIALOG) 抓 只取 純 檔名 檔案名稱
https://blog.xuite.net/merci0212/wretch/141175623-OpenFileDialog.filename%E5%8F%AA%E5%8F%96%E6%AA%94%E5%90%8D
using System.IO;
string filename = Path.GetFileName(OpenFileDialog.filename);
//filename就是所謂的檔案名啦!!!
//這個Path.GetFileName()函式可以得到檔案名。