C# 打開、另存文件


以txt文件為例
打開文件選擇框

 

private void btn_choose_Click(object sender, EventArgs e)
        {
            OpenFileDialog** InvokeDialog = new OpenFileDialog();
            InvokeDialog.Filter = "txt文件|*.txt";
            if (InvokeDialog.ShowDialog() == DialogResult.OK)
            {
                this.txt_path.Text = InvokeDialog.FileName;
                filepath = this.txt_path.Text;              
            }
        }

 

另存文件

 

private void btn_selRoute_Click(object sender, EventArgs e)
        {
            string localFilePath = "";
           SaveFileDialog  sfd = new SaveFileDialog();
            sfd.Filter= "txt文件(*.txt)|*.txt";
            sfd.FilterIndex= 1;
            sfd.RestoreDirectory= true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                localFilePath = sfd.FileName.ToString();
                string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
                this.txt_saveRoute.Text = localFilePath;
            }
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM