views:

165

answers:

3

Hi all, I have a link in a Gridview that I want opened in Windows Explorer (or explorer.exe).

<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>

and in codebehind I have this:

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

Obviously this doesn't work as Process.Start only works if I have full permissions, etc, etc. I heard that I can use Javascript to do this, but haven't succeeded so far. Basically, what I want is the exact link that is displayed in the grid to be opened when clicked. Any help would be much appreciated!

Thanks!

A: 

As you have found out starting processes on the client computer from a web site is not possible. You could redirect though to this web page:

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

Another option is to use an ActiveX control but this will work only on Internet Explorer.

Darin Dimitrov
A: 

(1) Please don't use javascript to start a local executable file (especially explorer.exe which is an important system file) because sometimes the firewall/anti-virus software will consider your action dangerous/baleful.

(2) Anyway executing a client user's programme via your website/web application is always not so friendly. I guess you want to execute "explorer.exe" to open a window to browse the local directory? If so, you can simulate a windows explorer window in your web page.

Danny Chen
A: 

I managed to resolved it easily:

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