我用asp:FileUpload和asp:Button控件创建了一个简单的.Net 4.6网站,以便用户可以浏览PC上的文件,然后将其上传到我的服务器上。
我已经将第一部分讲完了,如下所示。但是,我不知道如何将用户的文件获取到我的服务器。只是安装了IIS的Windows Server 2012。
这是我到目前为止所拥有的:
<asp:FileUpload CssClass="upload" ID="flImageFromComputer" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" CssClass="btn" />
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Try
If Me.flImageFromComputer.HasFile Then
With Me.flImageFromComputer
' *** not sure how to get it to the server ***
End With
End If
Catch ex As Exception
Response.Write(ex.ToString)
End Try
我已经尝试使用Google搜索,但实际上找不到有关如何将文件传输到服务器的任何信息。
任何帮助都会很棒! :)
谢谢!
答案 0 :(得分:2)
建议您不要使用Google搜索,而应该使用documentation。您会看到它包含一个SaveAs method。它应该可以满足您的需求。
Me.flImageFromComputer.SaveAs("c:\...\file.ext")
您必须确保正在运行的用户有权访问该路径。