SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Download pdf, word doc or display html from WebService - file stream help?

    Hi,

    I need some help with some C# .net code which allows the user to click on the relevant image and download either a pdf, word doc or display html in a new window.

    I have displayed some of the code below which I use to display the images in a repeater, can someone please provide me with some code to do the above. pdf will be received as binary response and html is string (html should have all html tags outside and including body removed, however any <h1>, <h2> 's within the body need to be replaced with <h3>'s


    Thanks in advance.

    puthsardarade



    aspx

    <asp:Repeater ID="rplist" OnItemDataBound="rplist_OnBound" runat="server">
    <ItemTemplate>
    <h3><%# Eval("recordTypes")%> Records</h3>
    <p>
    <asp:HiddenField runat="Server" Id="hidImages" Value ='<%# Eval("recordTypes")%>' />
    <asp:ImageButton runat="Server" ID="imgDoc" ImageUrl="~/img/word-icon.gif" OnClick="imgDoc_Click" /> <asp:ImageButton runat="Server" ID="imgPDF" ImageUrl="~/img/pdf-icon.gif" OnClick="imgPDF_Click" /> <asp:ImageButton runat="Server" ID="imgHTML" ImageUrl="~/img/html-icon.gif" OnClick="imgHTML_Click" />
    </ItemTemplate>
    </asp:Repeater>



    c#



    protected void rplist_OnBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
    Image img1 = e.Item.FindControl("imgDoc") as Image;

    Image img2 = e.Item.FindControl("imgPdf") as Image;

    Image img3 = e.Item.FindControl("imgHtml") as Image;

    HiddenField hfld = e.Item.FindControl("hidImage") as HiddenField;


    if (hfld != null)
    {
    //Check the value in hfld and set the visibility of the image buttons

    // img1, img2, img3 becomes your repeater image buttons and hfld becomes your hidImages control of your repeater (Contains value of the field)
    }
    }

  2. #2
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    An update on the above, I have found out that I need to use the MemoryStream class, so info on this can be found at: http://msdn.microsoft.com/en-us/libr...orystream.aspx

    So in summary my repeater will show numerous pdf images so I need to somehow pass through the value of the relevant one from imgPDF_Click and then allow the user to download this pdf file, I also need to do the same thing with html but before presenting this in a new window (html should have all html tags outside and including body removed, however any <h1>, <h2> 's within the body need to be replaced with <h3>'s) and finally imgDoc_Click for the word doc file again this would be exactly the same as the pdf event and will be retrieved as binary from the web service.



    Can anyone please help with the above by providing some code?

    Thanks in advance,

    G


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •