I have a code in VB.NET just to upload a file in ASP.NET WebForm. It is working perfectly in Firefox, Chrome and Safari. But the same code is unable to save the uploaded file in Microsoft Internet Explorer and Microsoft Edge, although there is no any error or exception in the application. I need someone's help to fix the issue. My .aspx code and code-behind file's code are as below:
WebForm1.ASPX
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="FileUploadTest.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="Uploader" runat="server" />
<asp:Button ID="cmdUpload" runat="server" Text="Upload" />
</div>
</form>
</body>
</html>
CodeBehind File
Imports System.IO
Public Class WebForm1
Inherits Page
Dim uploadDirectory As String = "C:\Uploads\"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub cmdUpload_Click(sender As Object, e As EventArgs) Handles cmdUpload.Click
Dim uniqueGuid As String = Guid.NewGuid.ToString
Dim tmpUploadDirectory As String = uploadDirectory & "\" & uniqueGuid
If Not Directory.Exists(tmpUploadDirectory) Then
Directory.CreateDirectory(tmpUploadDirectory)
End If
For Each f As HttpPostedFile In Uploader.PostedFiles
f.SaveAs(Path.Combine(tmpUploadDirectory, f.FileName))
Next
End Sub
End Class