Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you open a UNC path from ASP.NET

Status
Not open for further replies.

mrgulic

Technical User
Sep 18, 2001
248
US
My app retrieves all servers on the domain and populates a listbox with the server name. When server is clicked in the listbox, the shares on that server is listed in another listbox. When the share listbox is clicked, details about the share is displayed in labels, etc.

What I am trying to do is have a link built with the unc path that is retuned that you can click on and open windows explorer to that unc. I have been able to do this when i create a link staticly, but i have not been able to get it working dynamically.

This is the code that am using with the ImageButton control.

Code:
protected void ibtnSharePath_Click(object sender, ImageClickEventArgs e)
{
    HyperLink h = new HyperLink();
    h.NavigateUrl = "file://" + lblRoot.Text;
}

Thanks in advance for you time.
 
I don't know that this is the best way to occomplish my task but I wanted to share how I did it nonetheless.


Code:
System.Diagnostics.Process.Start("explorer.exe", lblRoot.Text);

This also work's, but it appears to open the explorer window behind IE, instead of out front.

Code:
System.Diagnostics.Process.Start(lblRoot.Text);

FYI: lblRoot.Text contains a string of \\server\sharename
 
What is not working in your first example (I haven't tried it but am curious)? Is the link simply not showing up? If that's the case then try also setting the text property of the hyperlink (I know that regular html hyperlinks won't show up if you don't have some text property).

Regards,

J
 
If this is what you meant

Code:
protected void ibtnSharePath_Click(object sender, ImageClickEventArgs e)
        {
            HyperLink h = new HyperLink();
            h.Text = "test";
            h.NavigateUrl = lblRoot.Text;
        }

then no, it didnt work. The end URL I saw when debugging was \\\\server\\sharename

Thanks for the idea. If you have anymore, I would be hapy to try.
 
In your example you just need to add the control to your page (you might need a placeholder for this if you want it in a specific location on the page).

Code:
HyperLink h = new HyperLink();
h.NavigateUrl = "\\Server\Share"
h.Text = "\\Server\Share";
//Add the control to the end of the page (this might get convered by another element so it would be best to add it to a specific container
Controls.Add(h);

Also, I assume that you don't actually want to open the share when you click the ImageButton. When you click the button you want to create the link. Then open the fileshare when then click the link, right?

J
 
I think I made a mistake (no dev environment in front of me).

Code:
HyperLink h = new HyperLink();
h.NavigateUrl = @"\\Server\Share";
h.Text = @"\\Server\Share";
//Add the control to the end of the page (this might get convered by another element so it would be best to add it to a specific container
Controls.Add(h);

If that doesn't work for you then I'll test it out tomorrow.

Regards,

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top