ASP.NET Hyperlink Control Showing wrong path

Adeel Mirza 121 Reputation points
2022-02-28T09:24:23.163+00:00

I am using this source code to specify a repository path to download files.

  1. In Web.Config
    <add key="Repository" value="D:\D Drive\MyApplication\RepotingService\SRC\Repository"/>
  2. Now in the CS File I used this source code to download the file. string Repository = WebConfigurationManager.AppSettings["Repository"].ToString();
        FileNameLink.NavigateUrl = Repository + "/AuthorizedUser/R1/" + gvITD.SelectedRow.Cells[9].Text;
        FileNameLink.Text = gvITD.SelectedRow.Cells[10].Text;
    

But when I bring my cursor to the hyperlink it the, it shows wrong path.

file:///D:/D%20Drive/MyApplication/RepotingService/SRC/Repository//AuthorizedUser/R1/2022

Why is it adding file:// before the Drive?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,273 questions
{count} votes

Accepted answer
  1. Sreeju Nair 11,616 Reputation points
    2022-02-28T12:49:51.187+00:00

    this is the default browser behavior. For. E.g. consider the following Html

    <a href="d:\test.html">testing</a>

    You may see the markup include the reference to the local disk. The browser will convert the link to the local disk to file:// format

    178429-image.png

    To understand whether ASP.Net actually converts the link to file:// format, please refer the source of the generated page.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,066 Reputation points
    2022-03-01T02:15:50.287+00:00

    Hi @Adeel Mirza ,
    I think you could use Server.MapPath to get the virtual path of the physical file.

    Server.MapPath(path)    
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments