C# OpenDialog如何获取打开文件的路径?
请问下面这个程序如何获取打开文件的全路径?谢谢!usingSystem;usingSystem.Collections.Generic;usingSystem.Compo...
请问下面这个程序如何获取打开文件的全路径?谢谢!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;namespace MostlyUsedDialog{ public partial class Form1 : Form { OpenFileDialog openFileDialog; public Form1() { InitializeComponent(); } private void openFile_Click(object sender, EventArgs e) { //声明打开文件对话框 openFileDialog = new OpenFileDialog(); /** *FileInfo myFile=new FileInfo(openFileDialog1.FileName); *FileName= myFile.FileName;//myFile.FileName为所需无路径文件名 */ //指出文件筛选列表 openFileDialog.Filter = "文本文件(*.txt)|*.*|所有文件(*.*)|*.*"; //指出默认使用的筛选器 openFileDialog.FilterIndex = 1; //指出恢复路径 openFileDialog.RestoreDirectory = true; //openFileDialog.InitialDirectory = @"F:\123"; //如果点击对话框上的“打开”按钮(如果用户取消表示没必要下一步操作) if (openFileDialog.ShowDialog(this) == DialogResult.OK) { string content = System.IO.File.ReadAllText(openFileDialog.FileName, Encoding.Default); richTextBox1.AppendText(content); } } }}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询