C#开发winform中OpenFileDialog的运用还可以多选
2015-08-06 08:33
435 查看
原文地址: /article/9978358.html
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();
}
}
}
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为 截取长度
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为 截取长度
相关文章推荐
- 2.2.3 Main方法;2.2.4 标识符及关键字;2.2.5 C#语句
- c#中的??运算符
- C#模板引擎 RazorEngine3.7的扩展 — 引入外部文件
- C# 进制转换(二进制、十六进制、十进制互转)
- C# DataGridView改变行颜色
- 使用C#格式化字符串 ~
- C#中 使用 System.Windows.Forms.Time 定时器
- 第二章 C#继承&继承类型&虚函数&抽象类&抽象函数&抽象方法&隐藏方法
- 新手浅谈C#Task异步编程
- c#中的模态对话框和非模态对话框
- C# 中如何调用DLL文件(分两种情况,托管与非托管)
- C#中何时使用dynamic
- c#构造函数
- c# for与foreach
- C# 键盘勾勒 打开,隐藏,关闭,截屏快捷键
- C#高级编程小结
- C#脚本引擎 CS-Script 之(二)——性能评测
- c#运行机制
- c#ref与out
- c#读写csv