locked
Listen to audio on file server RRS feed

  • Question

  • User1216627406 posted

    Greetings again.

    On the DB, we two fieldnames, one is called servername and the other is called filename.

    When the database is queried, it displays whatever servername is associated with a particular row of records.

    Same is the case with filename. This filename is an audio file of .WAV extension.

    For instance, servername = server1; filename=Grants

    Then we have url that when clicked, will play an audio message for anyone to listen to.

    The problem is the URL is not getting access to the audio files.

    Here is the link, part of GridView control.

    <asp:HyperLinkField DataNavigateUrlFields="filename" headertext="Recording" DataNavigateUrlFormatString="http://Archive/{servername from DB}/play_recording_wav.asp.net?filename='noop_'{0}'.wav" Text="Listen" />
    

    Essentially, On the DB, value for filename is Grants (just an example).

    However, on the server, it is saved as noop_Grants.wav

    So Servername comes from the DB, noop is hardcoded value appended to filename.

    .WAV is also hardcoded and appended to filename called Grants or any other name.

    I am having difficulty forming the url string above.

    Your assistance is greatly appreciated.

    , so is .wav

    Basically, this is what I would like to append to the url:

    src = "archives/"+ '<%# Eval("Servername") %> + "noop_" + Eval("filename") %>' + ".wav"

    So the URL looks like this:

    http://archives/server1/noop_Grants.wav

    Thursday, May 23, 2019 3:39 PM

Answers

  • User-1174608757 posted

    Hi simflex,

    According to your description, I have made a sample here. I suggest that you could enter multiply column in datanavigateurlfields tag of HyperLinkField, then you could format url  in DataNavigateUrlFormatString. Here is the demo, I hope it could help you.

    aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server">
                    <Columns>
    <%--name students is column name in db--%> <asp:hyperlinkfield Text="link" datatextformatstring="{0:c}" datanavigateurlfields="name,students" datanavigateurlformatstring="http://Archive/{0}/play_recording_wav.asp.net?filename={1}.wav" headertext="Price" target="_blank" /> </Columns> </asp:GridView> </div> </form> </body> </html>

    aspx.cs:

    public partial class Hyl : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string sql = "select * from students";
                    GridView1.DataSource = SqlHelper.ExecuteDataTable(sql);
                    GridView1.DataBind();
                }
            }
        }

    You could see as below:

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 24, 2019 2:52 AM

All replies

  • User753101303 posted

    Hi,

    Not sure what happens. If you have a real file available from http://archives/server1/noop_Grants.wav (you used also archive), it could be that you have to add a mime type for wav files : https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap

    By default IIS doesn't serve a file for which it doesn't have a registered mime type.

    Or could it be that the client side browser doesn't have access to a server named "archives" or that this server doesn't know how to serve what is located at /server1/noop_Grants.wav ?

    Thursday, May 23, 2019 4:21 PM
  • User1216627406 posted

    Thanks Patrice for your help.

    The issue though is that I am not able to append the rest of the fields to the URL:

    <asp:HyperLinkField DataNavigateUrlFields="filename" headertext="Recording" DataNavigateUrlFormatString="http://Archive/{servername from DB}/play_recording_wav.asp.net?filename='noop_'{0}'.wav" Text="Listen" />

    I already have mime type configured in IIS.

    I just need help making sure that DataNigateUrlFormatString has the fields and the hardcoded fields added correctly to that URL.

    Thursday, May 23, 2019 4:45 PM
  • User-1174608757 posted

    Hi simflex,

    According to your description, I have made a sample here. I suggest that you could enter multiply column in datanavigateurlfields tag of HyperLinkField, then you could format url  in DataNavigateUrlFormatString. Here is the demo, I hope it could help you.

    aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:GridView ID="GridView1" runat="server">
                    <Columns>
    <%--name students is column name in db--%> <asp:hyperlinkfield Text="link" datatextformatstring="{0:c}" datanavigateurlfields="name,students" datanavigateurlformatstring="http://Archive/{0}/play_recording_wav.asp.net?filename={1}.wav" headertext="Price" target="_blank" /> </Columns> </asp:GridView> </div> </form> </body> </html>

    aspx.cs:

    public partial class Hyl : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string sql = "select * from students";
                    GridView1.DataSource = SqlHelper.ExecuteDataTable(sql);
                    GridView1.DataBind();
                }
            }
        }

    You could see as below:

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 24, 2019 2:52 AM
  • User1216627406 posted

    This is great stuff.

    Thank you so much.

    That worked.

    I have just one more issue to deal with and I will be done with this project.

    I am closing this and will post after.

    Many thanks for your brilliant solution.

    Thursday, May 30, 2019 12:30 AM