【问题标题】:How can I show up OpenFileDialog class in ASP.NET?如何在 ASP.NET 中显示 OpenFileDialog 类?
【发布时间】:2012-10-06 12:57:00
【问题描述】:

我想在我的 ASP .NET Web 应用程序中显示一个 OpenFileDialog 框。我正在用 c# 编写。我想创建一个带有图像的用户帐户,因此我需要从计算机中选择图像并将其保存到数据库中。我该如何实现它。

【问题讨论】:

  • 您正在寻找 FileUpload 元素.. 而不是 OpenFileDialog(即 WinForms)。
  • 添加<asp:fileupload> 控件并阅读文档。
  • @RQDQ:问题中明确指出该应用程序是 ASP.NET
  • 我已经重新标记了这个问题以避免将来出现混淆

标签: c# asp.net openfiledialog


【解决方案1】:

与上面的 Tigran 几乎相同,但我发现我需要稍微更改 JavaScript 以使用 getElementById("...") 来识别要单击 () 的按钮。如果我只是在 HTML/CSS Tigran 的代码中执行此操作,但当我在 .aspx 文件中使用它时,我需要进行更改。

.aspx

<input type="file" id="fileLoader" name="files" title="Load File" />   
<asp:Button ID="LoginButton" runat="server"  Text="ASP click Me" onclientclick="openfileDialog()"  />

JavaScript

function openfileDialog() {
         document.getElementById("fileLoader").click();
     }

css

#fileLoader{
display:none;}

【讨论】:

    【解决方案2】:

    可以使用

    做到这一点
       <input type="file"  id="fileLoader" name="files" title="Load File" ...
    

    通常的技巧是使其不可见,并在单击一些可见 工件时(styled linkimagebutton...随便)模拟点击fileLoader

     $("#fileLoader").click();
    

    【讨论】:

      【解决方案3】:

      你不能在 ASP.NET 中使用那个 Windows 窗体类,你应该使用 FileUpload class/control

      或查看其他替代方案:Uploading Files in ASP.net without using the FileUpload server control

      【讨论】:

        【解决方案4】:

        你不能。 OpenFileDialog 是用于桌面应用程序的东西。

        【讨论】:

        • 很明显,OP 是在询问 analogy。他只是“在太空中航行”,寻找一些解决方案。
        • @Tigran:你可能是对的,但我认为你和我对“清除”这个词的定义不同。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-30
        • 2012-11-07
        相关资源
        最近更新 更多