【发布时间】:2017-12-06 00:05:48
【问题描述】:
我在 VB.NET 中有一个代码,只是为了在 ASP.NET WebForm 中上传一个文件。它在 Firefox、Chrome 和 Safari 中运行良好。但是相同的代码无法将上传的文件保存在 Microsoft Internet Explorer 和 Microsoft Edge 中,尽管应用程序中没有任何错误或异常。我需要有人帮助解决这个问题。我的 .aspx 代码和代码隐藏文件的代码如下:
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>
代码隐藏文件
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
【问题讨论】:
标签: asp.net .net vb.net webforms web-controls