I'm uploading a file and want to detect its file extension, so I can add it onto the path of the file, for example 435.jpg, in classic asp I used - File.ext
How do you detect it in ASP.Net (
VB)?
Also, how do you overwrite files? Here is my sub
Sub Upload_Click(Sender as Object, e as EventArgs)
UploadDetails.visible = True
' Let us recover only the file name from its fully qualified path at client
Dim strFileName as string
strFileName = MyFile.PostedFile.FileName
Dim c as string = System.IO.Path.GetFileName(strFileName) ' only the attched file name not its path
' Let us Save uploaded file to server at C:\ServerFolder
Dim strSQL2 As String = "UPDATE Product set Prod_Image = " & _
" '" & c & "' WHERE ProdID = " & Request("ProdID")
Connect()
Dim dbComm As New SqlCommand(strSQL2, objConnection)
dbComm.ExecuteNonQuery()
Disconnect()
MyFile.PostedFile.SaveAs(getAssetsPath + c)
UploadDetails.Overwrite = True
Response.Redirect("products.aspx?ProdRangeID=" & Request("ProdRangeID"))
End Sub