Read and Download Response from URL using C# .Net

Last Reply on Oct 07, 2015 06:54 AM By Shashikant

Posted on Oct 06, 2015 02:14 AM

This URL A :

generates into URL B:

You can try it by copying and paste the URL Link A  on your browser and  you will see the URL Link  A  generates the URL Link B, afterwards I will need to copy and paste mannually  the URL Link B,  which will display an image file for your view.  This will give you an idea what I am trying to do.

I would like to be able in the code-behind clicking the button from URL A to URL B to display an image in the popup window. How to do this process in the code-behind?

See the code below:


Protected Sub BtnSAS_Click(sender As Object, e As EventArgs) Handles BtnSAS.Click

Dim IdNumber As String = TextNumber.Text.Trim()

Dim UrlA as string =”” & IDNumber & ”.pdf&passKey=RecorderAz4ass3ey”

'generate into URL B

ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "Key", "'','PDFViewer','menubar=0, location=1, toolbars=1, scrollbars= 1, resizable=1, width=750,height=775, top=150, left=220')", True)

End Sub

Your help is greatly appreciated.  Thanks.

Posted on Oct 07, 2015 06:54 AM

Hi slb2013,

Here I have created sample that full-fill your requirement.


    Enter Id Number : <asp:TextBox runat="server" ID="TextNumber"></asp:TextBox>&nbsp;&nbsp;
    <asp:Button ID="btnSAS" Text="SAS" runat="server" OnClick="BtnSAS_Click" />


protected void BtnSAS_Click(object sender, EventArgs e)
    string IdNumber = TextNumber.Text.Trim();
    string UrlA = "" + IdNumber + ".pdf&passKey=RecorderAz4ass3ey";
    string UrlB = ResFromServer(UrlA);
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Key", "'" + UrlB + "','PDFViewer','menubar=0, location=1, toolbars=1, scrollbars= 1, resizable=1, width=750,height=775, top=150, left=220')", true);

public string ResFromServer(string url)
    string location = string.Copy(url);
    string responseFromServer = string.Empty;
    if (!string.IsNullOrEmpty(location))
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(location);
        request.AllowAutoRedirect = false;
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            Stream dataStream;
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            responseFromServer = reader.ReadToEnd();
    return responseFromServer;