【问题标题】:Linkbutton to open Windows Explorer from Gridview从 Gridview 打开 Windows 资源管理器的链接按钮
【发布时间】:2010-06-04 06:17:41
【问题描述】:

我希望在 Windows 资源管理器(或 explorer.exe)中打开 Gridview 中的链接。

<asp:GridView  ID="GridView1"runat="server" >
   <Columns>
       <asp:TemplateField>
           <ItemTemplate>
               <asp:LinkButton ID="DeploymentLocation" runat="server" CommandName="OpenLink" 
                   Text='<%# Eval("DeploymentLocation") %>' CommandArgument='<%# Eval("DeploymentLocation") %>'  />
           </ItemTemplate>
        </asp:TemplateField>
   </Columns>

在代码隐藏中我有这个:

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
          Process.Start("explorer.exe", "/n," + e.CommandArgument.ToString());
    }

显然这不起作用,因为 Process.Start 仅在我拥有完全权限等情况下才有效。我听说我可以使用 Javascript 来执行此操作,但到目前为止还没有成功。 基本上,我想要的是单击时要打开的网格中显示的确切链接。任何帮助将不胜感激!

谢谢!

【问题讨论】:

    标签: c# asp.net javascript gridview asp.net-2.0


    【解决方案1】:

    您发现无法从网站在客户端计算机上启动进程。你可以重定向到这个网页:

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Response.Redirect(e.CommandArgument.ToString());
    }
    

    另一种选择是使用ActiveX control,但这仅适用于 Internet Explorer。

    【讨论】:

      【解决方案2】:

      (1) 请不要使用javascript启动本地可执行文件(尤其是explorer.exe,它是一个重要的系统文件),因为有时防火墙/杀毒软件会认为您的操作是危险的/有害的。

      (2) 无论如何,通过您的网站/Web 应用程序执行客户端用户的程序总是不太友好。我猜你想执行“explorer.exe”打开一个窗口浏览本地目录?如果是这样,您可以在网页中模拟 Windows 资源管理器窗口。

      【讨论】:

        【解决方案3】:

        我设法轻松解决了:

        <ItemTemplate>
           <asp:HyperLink Text='<%# Eval("DeploymentLocation") %>'  id="DeploymentLocation" runat="server" Target="_blank" NavigateUrl='<%# "file:///" + Eval("DeploymentLocation").ToString() %>' ></asp:HyperLink>
        </ItemTemplate>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-25
          • 1970-01-01
          • 2013-10-27
          相关资源
          最近更新 更多