C#开发winform中OpenFileDialog的运用还可以多选

原文地址: http://blog.csdn.net/njust_qhzt/article/details/8810315

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Runtime.InteropServices;
using System.IO;

private void button4_Click(object sender, System.EventArgs e)
{
Stream mystream;
OpenFileDialog openfiledialog1=new OpenFileDialog();
openfiledialog1.Multiselect=true;//允许同时选择多个文件 
openfiledialog1.InitialDirectory="c:\\";
openfiledialog1.Filter="txt files(*.txt)|*.txt|All files(*.*)|*.*";
openfiledialog1.FilterIndex=2;
openfiledialog1.RestoreDirectory=true;
if(openfiledialog1.ShowDialog()==DialogResult.OK)
{
if((mystream=openfiledialog1.OpenFile())!=null)
{
this.textBox2.Text="";
for(int fi=0;fi<openfiledialog1.FileNames.Length;fi++)
{
this.textBox2.Text+=openfiledialog1.FileNames[fi].ToString();
}
mystream.Close();
}
}
}

 

C#通过文件路径获取文件名

string fullPath = @"/WebSite1/Default.aspx";

string filename = System.IO.Path.GetFileName(fullPath);//文件名 “Default.aspx”
string extension = System.IO.Path.GetExtension(fullPath);//扩展名 “.aspx”
string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fullPath);// 没有扩展名的文件名 “Default”

 

 

string str1 = "1234567";

string str2= str1.SubString(0,3); // str2="123";

string str3 = str1.SubString(2,3); //str3 = "345";

SubString(m, n) ; m为需要截取的字符串索引位置, n为 截取长度


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值