Jag har ett problem som det säkert finns en enkel lösning på.Variabel i formtagg.
Koden nedan laddar upp en bild till en katalog på servern, efter att bilden är uppladdad så skall den visas den i imageboxen.
Frågan är, hur får jag in filnamnet (benämnt ***filename*** nedan) i Formtaggen?
<%@ Import namespace="System.IO"%>
<HTML>
<HEAD>
<title>Uploading a File</title>
<script language="VB" runat="server">
Dim savePath As String = "C:\Inetpub\wwwroot\development\imageupload\images\"
Sub Upload_Click(source As Object, e As EventArgs)
If Not (uploadedFile.PostedFile Is Nothing) Then
Try
Dim postedFile = uploadedFile.PostedFile
Dim filename As String = Path.GetFileName(postedFile.FileName)
Dim contentType As String = postedFile.ContentType
Dim contentLength As Integer = postedFile.ContentLength
postedFile.SaveAs(savePath & filename)
message.Text = postedFile.Filename & " uploaded" & _
"<br>content type: " & contentType & _
"<br>content length: " & contentLength.ToString()
Catch exc As Exception
message.Text = "Failed uploading file"
End Try
End If
End Sub
</script>
</HEAD>
<body>
<form id="Form1" encType="multipart/form-data" runat="server">
<P><asp:image id="Image1" runat="server" ImageUrl="/imageupload/images/" & ***filename*** ></asp:image></P>
<P> </P>
<P>Select File to Upload: <input id="uploadedFile" type="file" name="uploadedFile" runat="server">
</P>
<p><input id="upload" type="button" value="Upload" name="upload" runat="server" OnServerClick="Upload_Click">
<p>
<asp:Label id="message" runat="server" />
</form>
</P>
</body>
</HTML>