是否有一种简单的方法来获取文件名?
我正在尝试这样的事情而没有运气; /
Protected Sub ASPxUploadControl1_FileUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs) Handles ASPxUploadControl1.FileUploadComplete
Dim fileInfo As New FileInfo(e.UploadedFile As String)
答案 0 :(得分:0)
是否有一种简单的方法来获取文件名?
是
Dim fileName As String = System.IO.Path.GetFileName(e.filename)
这是一个完整的示例,其中只允许使用Excel文件:
Private Shared allowedExtensions As New List(Of String)(New String() {".xls", ".xlsx"})
Private ASPxUploadControl1_FileUploadComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) ASPxUploadControl1.FileUploadComplete
If e.state = AjaxControlToolkit.AsyncFileUploadState.Success Then
Dim fileExtension As String = System.IO.Path.GetExtension(e.filename)
If allowedExtensions.Contains(fileExt) Then
Dim fileName As String = System.IO.Path.GetFileName(e.filename)
Dim appDir As String = Hosting.HostingEnvironment.ApplicationPhysicalPath
Dim subDir As String = My.Settings.UploadSubDirectory
Dim path As String = appDir & subDir & fileName
ASPxUploadControl1.PostedFile.SaveAs(path)
ASPxUploadControl1.FileContent.Close()
End If
End If
End Sub
答案 1 :(得分:0)
文档(包括示例)存在here。
给出的例子是在C#中,但想法是一样的。
文档示例:
protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e) {
if (e.IsValid) {
ASPxUploadControl1.PostedFile.SaveAs(MapPath("Images/" +
ASPxUploadControl1.PostedFile.FileName));
}
}