如何在按钮单击中生成文件选择窗口?

时间:2015-06-16 04:28:40

标签: asp.net

我想在点击按钮时打开文件选择窗口。

如何在不使用文件上传器控件的情况下打开文件选择窗口?

2 个答案:

答案 0 :(得分:0)

请尝试以下代码:

private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog openFileDialog1 = new OpenFileDialog();

        // Set filter options and filter index.
        openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
        openFileDialog1.FilterIndex = 1;

        openFileDialog1.Multiselect = true;

        // Call the ShowDialog method to show the dialog box.
         openFileDialog1.ShowDialog();

        // Process input if the user clicked OK.

    }

如果对您有帮助,请将答案标记为正确。

答案 1 :(得分:0)

我发布了更新的小提琴。这对你有帮助!

<强> HTML

<form action="" method="post" enctype="multipart/form-data">
    <div class="upload">
        <input type="file" name="upload"/>
    </div>
</form>

<强> CSS

div.upload {
    width: 157px;
    height: 57px;
    background: url(https://lh6.googleusercontent.com/-dqTIJRTqEAQ/UJaofTQm3hI/AAAAAAAABHo/w7ruR1SOIsA/s157/upload.png);
    overflow: hidden;
}

div.upload input[type=file] {
    display: block !important;
    width: 157px !important;
    height: 57px !important;
    opacity: 0 !important;
    overflow: hidden !important;
}

http://jsfiddle.net/Isakkiraj/mxq9R/4632/