<html>
<head>
<script language="VB" runat="server">
Sub Upload(Source As Object, e As EventArgs)
If Not (myFile.PostedFile Is Nothing) Then
Dim intFileLength as Integer
Dim ImgFileNamePath as String
Dim ImgFileName as String
if myFile.PostedFile.ContentType <> "image/pjpeg" then
lbResult.Text = "Tipo di file non valido"
else
if myFile.PostedFile.ContentLength > 50000 then
lbResult.Text = "File troppo grande"
else
try
ImgFileNamePath = myFile.PostedFile.FileName
intFileLength = Instr(1, StrReverse(ImgFileNamePath), "\")
ImgFileName = Mid(ImgFileNamePath, (Len(ImgFileNamePath)-intFileLength)+2)
myFile.PostedFile.SaveAs("c:\wwwroot\sito\immagini\" & ImgFileName)
lbResult.Text = "File salvato"
catch ex As Exception
lbResult.Text = "Errore nel salvataggio:<br>" & ex.Message
end try
End If
End If
End If
End Sub
</script>
</head>
<body>
<form name="Form1" runat="server">
<INPUT id="myFile" type="file" name="myFile" runat="server"><BR>
<INPUT id="Button1" type="button" value="Upload" name="Button1" runat="server" OnServerClick="Upload"><BR><BR>
<asp:Label ID="lbResult" Runat="server"></asp:Label>
</form>
</body>
</html>