打开对话框
1 private void openFileDialogBTN_Click(object sender, System.EventArgs e){
3 OpenFileDialog openFileDialog=new OpenFileDialog();
4 openFileDialog.InitialDirectory="c:\\";//注意这里写路径时要用c:\\而不是c:\
5 openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件|*.*";
6 openFileDialog.RestoreDirectory=true;
7 openFileDialog.FilterIndex=1;
11 File fileOpen=new File(fName);
12 isFileHaveName=true;
13 richTextBox1.Text=fileOpen.ReadFile();
14 richTextBox1.AppendText("");
15
16 }
4 openFileDialog.InitialDirectory="c:\\";//注意这里写路径时要用c:\\而不是c:\
5 openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件|*.*";
6 openFileDialog.RestoreDirectory=true;
7 openFileDialog.FilterIndex=1;
8 openFileDialog.ShowDialog();10 fName=openFileDialog.FileName;
11 File fileOpen=new File(fName);
12 isFileHaveName=true;
13 richTextBox1.Text=fileOpen.ReadFile();
14 richTextBox1.AppendText("");
15
16 }
Jquery中打开对话框
html
<body>
<div>
<input type="file" id="file" style="display:none" mce_style="display:none">
<input type="button" value="下载" onclick="xiazai()"/>
</div>
</body>
<script>
$(function() {
});
function xiazai() {
var s = document.getElementById("file");
s.click();
var str = s.value;//获取文件路径
alert(str);//在这里你可以进行自己的工作
}
</script>