This is a migrated thread and some comments may be shown as answers.

Hyperlink to a file on my local Computer/Share Drive

2 Answers 275 Views
Menu
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Veteran
David asked on 25 Aug 2020, 11:47 PM

Hello All, 

I was doing some searching and I can't find how to do a Hyperlink to a file on my local computer/share drive in HTML.Kendo().Menu()

 

This is my code

@(Html.Kendo().Menu()
                .Name("Menu")
                .Direction(MenuDirection.Left)
                .Orientation(MenuOrientation.Vertical)
                .Scrollable(true)
                .Items(items =>
                {
                    items.Add().Text("Phone List").Url("file:///C:\Users\D\Desktop/Phone.pdf");
                    items.Add().Text("Pager List");

})

 

I'm trying to make so when a user clicks on my "Phone List" menu item, it then opens up a PDF with the relevant information in a new browser tab. I know the link works, because I can click it and it opens up the pdf in a browser. Any help would be appreciated. 

2 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
Veteran
answered on 25 Aug 2020, 11:49 PM

I just noticed, the slashes are incorrect. 

This is the correct code I'm using.

@(Html.Kendo().Menu()
                .Name("Menu")
                .Direction(MenuDirection.Left)
                .Orientation(MenuOrientation.Vertical)
                .Scrollable(true)
                .Items(items =>
                {
                    items.Add().Text("Phone List").Url("file:///C:/Users/D.D11/Desktop/Phone.pdf");
                    items.Add().Text("Pager List");
                })

0
Dimitar
Telerik team
answered on 27 Aug 2020, 11:39 AM

Hi,

Opening URLs to local files is blocked by browsers and clicking on the item you should get the following error in the console - "Not allowed to load local resource:". The reason for this error and some workaround are commented in the following StackOverflow thread. The same is reproducible even with a simple anchor tag and href to the same local resource.

To open a pdf file from a Menu item, the file should be placed on a location within the scope of the app or on another hosted URL, e.g.:

items.Add().Text("Pager List").Url("~/Content/web/pdfViewer/sample.pdf").LinkHtmlAttributes(new { target = "blank" });
items.Add().Text("Pager List").Url("https://demos.telerik.com/aspnet-mvc/Content/web/pdfViewer/sample.pdf").LinkHtmlAttributes(new { target = "blank" });

The .LinkHtmlAttributes(new {target = "blank"}) sets target="blank" attribute to the URL, thus opening the file in a new tab.

I hope this is helpful.

Regards,
Dimitar
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Menu
Asked by
David
Top achievements
Rank 1
Veteran
Answers by
David
Top achievements
Rank 1
Veteran
Dimitar
Telerik team
Share this question
or