1. 程式人生 > >C#開發winform中OpenFileDialog的運用還可以多選

C#開發winform中OpenFileDialog的運用還可以多選

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為 擷取長度