datalist navigate url convert from file:/// to http:// RRS feed

  • Question

  • User181930479 posted

    im fetching data from sql server and displaying the filename and its fullpath as a link , but when i hover overthe link im getting :

    file:///D://etc...... .html

    so when i click on it nothing happens 

    below is my code :

    <asp:HyperLink ID="HyperLink1" CssClass="list-group-item" runat="server" NavigateUrl= '<%# Eval ("FullPath") %>' Text='<%# Bind("FileName") %>' Target="ccmdemo"></asp:HyperLink>

    the target is an iframe on the same page .

    Any hint please ?

    Tuesday, March 13, 2018 6:55 AM

All replies

  • User-1716253493 posted

    I suggest you to store filename only, if all files located in same folder

     NavigateUrl= '<%# Eval ("Filename","http://domain/folder/{0}") %>'

    Or store folder + filename like "foldername/filename.ext" in database, if the files stored in multiple folders

    You can do

    NavigateUrl= '<%# Eval ("filepath","~/dokumens/{0}") %>'

    to replace d:\folder\filename.ext to http://domain/folder/filename.ext you can do this in sql

    SELECT replace(fullpath,'d:\','http://') as fullpath

    Tuesday, March 13, 2018 8:46 AM
  • User-707554951 posted

    Hi NAF

    You full path stored in database should be as below:


    Note: Capture.PNG stored in Images folder

    Working code as below:

      <asp:DataList ID="dlCustomers" runat="server" RepeatColumns="3" CellSpacing="3" RepeatLayout="Table">
                        <table class="table">
                                <th colspan="2">
                                    <b><%# Eval("Name") %></b>
                                <td colspan="2">
                                    <asp:HyperLink ID="HyperLink1" CssClass="list-group-item" runat="server" NavigateUrl='<%#Eval("FullPath") %>' 
                                        Text='<%# Bind("Name") %>' Target="ccmdemo"></asp:HyperLink>


     protected void Page_Load(object sender, EventArgs e)
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[] { new DataColumn("Name"), new DataColumn("FullPath") });
                dt.Rows.Add("Name1", @"..\Images\Capture2.PNG");
                //following code not work for you 
                dt.Rows.Add("Name2", @"C:\Users\v-guzou\Documents\Visual Studio 2015\Projects\CaseTest\CaseTest\Images\Capture2.PNG");
                dt.Rows.Add("Name3", @"C:\Users\v-guzou\Documents\Visual Studio 2015\Projects\CaseTest\CaseTest\Images");
                dt.Rows.Add("Name4", @"C:\Users\v-guzou\Documents\Visual Studio 2015\Projects\CaseTest\CaseTest\Images");
                dlCustomers.DataSource = dt;


    Best regards


    Wednesday, March 14, 2018 2:36 AM