当前位置: 首页 > news >正文

c#获取文件路径

 

Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 获取文件路径
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private string filepath;

        
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        
{
            openFileDialog1.FileName 
= "*.txt";
            openFileDialog1.Filter 
= "接线图(*.txt)|*.txt";
            openFileDialog1.RestoreDirectory 
= true;
            openFileDialog1.FilterIndex 
= 1;
            
//openFileDialog1.ShowDialog();
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            
{
                FileStream fs 
= new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                FileInfo info 
= new FileInfo(openFileDialog1.FileName);
                filepath 
= info.ToString ();
            }

        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            StreamReader sr;
            
string s;
            
try
            
{
                sr 
= File.OpenText(filepath);
                s 
= sr.ReadToEnd();
                richTextBox1.Text 
= s.ToString();
                sr.Close();
            }

            
catch(Exception ex)
            
{
                MessageBox.Show(
"文件不存在");
            }

        }


        
private void panel1_Paint(object sender, PaintEventArgs e)
        
{
            
if(filepath !="")
            
{
                MessageBox .Show (
"buweikong");
            }

        }


    }

}

转载于:https://www.cnblogs.com/cxfcxf8/archive/2008/05/01/1179086.html

相关文章:

  • 条款二 : 运行时常量(readonly)优于编译时常量(const)
  • SQL Server 2005新功能
  • 是DataGrid的某数字内容列可编辑,并且以NumericStepper组件改变数值。
  • 找工作要做的十件事
  • 什么是数据恢复技术
  • [InnoDB系列] -- SHOW INNODB STATUS 探秘
  • 服务器中的地震仪,MOM2005+SP1部署指南(MOM2005系列之一)
  • 网络硬盘drop.io的使用
  • 1904年 圣路易斯 第三届奥运会
  • 20080605-昨日回顾今日计划
  • 机器人也有女性,Sega E.M.A登场
  • Mastering Oracle SQL学习笔记(join句法专题第八部份)
  • Microsoft .Net 框架 SDK 快速入门教程
  • 杂语
  • SAP BC427 课程中文自学笔记
  • CentOS7简单部署NFS
  • download使用浅析
  • JavaScript 是如何工作的:WebRTC 和对等网络的机制!
  • JS专题之继承
  • puppeteer stop redirect 的正确姿势及 net::ERR_FAILED 的解决
  • Python连接Oracle
  • Ruby 2.x 源代码分析:扩展 概述
  • Shell编程
  • Zepto.js源码学习之二
  • 关于Android中设置闹钟的相对比较完善的解决方案
  • 京东美团研发面经
  • 前端技术周刊 2019-01-14:客户端存储
  • 前端知识点整理(待续)
  • 浅谈JavaScript的面向对象和它的封装、继承、多态
  • 如何进阶一名有竞争力的程序员?
  • 试着探索高并发下的系统架构面貌
  • 腾讯优测优分享 | 你是否体验过Android手机插入耳机后仍外放的尴尬?
  • ​Linux·i2c驱动架构​
  • ​云纳万物 · 数皆有言|2021 七牛云战略发布会启幕,邀您赴约
  • #AngularJS#$sce.trustAsResourceUrl
  • #免费 苹果M系芯片Macbook电脑MacOS使用Bash脚本写入(读写)NTFS硬盘教程
  • #我与Java虚拟机的故事#连载01:人在JVM,身不由己
  • (bean配置类的注解开发)学习Spring的第十三天
  • (C语言)fread与fwrite详解
  • (pytorch进阶之路)扩散概率模型
  • (二)学习JVM —— 垃圾回收机制
  • (附源码)spring boot校园健康监测管理系统 毕业设计 151047
  • (五)大数据实战——使用模板虚拟机实现hadoop集群虚拟机克隆及网络相关配置
  • (一)SpringBoot3---尚硅谷总结
  • (原創) 物件導向與老子思想 (OO)
  • (转)机器学习的数学基础(1)--Dirichlet分布
  • (轉貼) 資訊相關科系畢業的學生,未來會是什麼樣子?(Misc)
  • .equals()到底是什么意思?
  • .NET Core 中的路径问题
  • .NET 设计模式初探
  • .NET 使用配置文件
  • .net 托管代码与非托管代码
  • .NET 中 GetHashCode 的哈希值有多大概率会相同(哈希碰撞)
  • .NET开发者必备的11款免费工具
  • .php文件都打不开,打不开php文件怎么办