locked
Upload an image and display it on next page - ASP.NET RRS feed

  • Question

  • Hey guys,

    I'm trying to allow the user to upload an image to the server (this part works) and display it on the next page (this part doesn't). I've got two files, imageuploadtext.aspx, which has the following code:

     

    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.IO" %>
    
    <html>
    
    <head>
    
    <script language="VB" runat="server">
    
     Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    
     If imageupload1.HasFile Then
     imageupload1.SaveAs(Server.MapPath(".") + "/uploadedimages/" & imageupload1.FileName)
     Label1.Text = "Received " & imageupload1.FileName & " Content Type " & imageupload1.PostedFile.ContentType & " Length " & imageupload1.PostedFile.ContentLength
     Else
     Label1.Text = "No uploaded file"
     End If
    
     End Sub
    
    </script>
    
    </head>
    
    <body>
    
    <form id="imguplad" runat=server>
    
    <asp:FileUpLoad id="imageupload1" AlternateText="You cannot upload files" runat="server" />
    <asp:Button id="Button1" Text="Upload" OnClick="Button1_Click" runat="server" />
    <asp:Label id="Label1" runat="server" />
    <input type="button" value="Click here when image is uploaded"
    onClick="location.href='imageloadtest.aspx';">
    </form>
    
    </body>
    
    </html>

     

    And the second file is imageloadtext.aspx, which has this short code:

     

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.IO" %>
    
    <html>
    
    <head>
    
    </head>
    
    <body>
    
    <img id="image" src="<%Server.MapPath(".")+"/uploadedimages/"+Request.Form["imageupload1.FileName"]%>" />
    
    </body>
    
    </html>
    

     

    As I said, the upload works fine and the file is received. But I can't get the source to display the correct image on the second page. Could it be to do with the fact the first page is VB and the second is C#? If so what code would I replace the C# with for it to work with VB? By the way, I'm currently getting a ";" expected on the image source line which I'm not sure where it goes, that might be it?

    Thanks for your help!

    John

    • Moved by Rudedog2 Saturday, August 7, 2010 2:16 PM ASP.NET is off topic (From:Visual C# General)
    Saturday, August 7, 2010 12:27 PM

Answers


  • You should ask ASP.Net questions on http://forums.asp.net.  You will likely get more responses, as the question seems off topic on this board.

    --
    Mike
    • Marked as answer by Rudedog2 Saturday, August 7, 2010 2:16 PM
    Saturday, August 7, 2010 12:33 PM

All replies


  • You should ask ASP.Net questions on http://forums.asp.net.  You will likely get more responses, as the question seems off topic on this board.

    --
    Mike
    • Marked as answer by Rudedog2 Saturday, August 7, 2010 2:16 PM
    Saturday, August 7, 2010 12:33 PM
  • Ah right, sorry about that!
    Saturday, August 7, 2010 12:42 PM