Jag använder ett "webbhotell" där jag har en vad jag tycker borde vara en simpel filuppladdningsfunktion. Det har fungerat i ett par månader utan problem och nu så fungerar det inte längre, det enda som "webbhotellet" säger är att de har uppdaterat säkerhetspatchar från Microsoft.
Är det något som ser fel ut i denna kod, jag är tyvärr nybörjare på ASP.NET...
<script language="VB" runat=server>
Sub DoUpload(Sender As Object, e As System.EventArgs)
Dim sPath as String
Dim sFile as String
Dim sFullPath as String
Dim sSplit() as String
Dim sPathFriendly as String
'Upload to same path as script
'Internet Anonymous User must have write permissions
sPath = Server.MapPath(".")
If Right(sPath, 1) <> "\" then
sPathFriendly = sPath 'Friendly path name for display
sPath = sPath & "\media\"
Else
sPathFriendly = Left(sPath, Len(sPath) - 1)
End If
'Save as same file name being posted
'The code below resolves the file name
'(removes path info)
sFile = txtUpload.PostedFile.FileName
sSplit = Split(sFile, "\")
sFile = sSplit(Ubound(sSplit))
sFullPath = sPath & sFile
Try
txtUpload.PostedFile.SaveAs(sFullPath)
lblResults.Text = "Upload of File " & sFile & " succeeded. Please close this window"
Catch Ex as Exception
lblResults.Text = "Upload of File " & sFile & " to " & sPathFriendly & " failed for the following reason: " & Ex.Message
Finally
lblResults.Font.Bold = True
lblResults.Visible = true
End Try
End Sub
</script>
<html>
<body>
<form enctype="multipart/form-data" runat=server>
Select File To Upload:
<input id="txtUpload" type=file runat=server>
<br />
<asp:button id=btnUpload Text="Upload File" OnClick="DoUpload" runat=server/>
<hr noshade>
<asp:label id="lblResults" Visible=false runat=server/>
</form>
</body>
</html>