我的页面上有一个AsynchFileUpload,出于某种原因,当我尝试使用它将文件保存到服务器时,它就会崩溃。
控件允许我在本地选择一个文件,它在文本框中显示本地文件路径,但是当我点击我页面上的一个按钮时,我将用它来提交所有细节,然后上传页面一切都出错了,我从AsynchFileUploader获得了Null Ref Exception。
我的上传器非常基本,看起来像:
<cc1:AsyncFileUpload runat="server"
ID="AsyncFileUpload2"
Enabled="true"
Visible="true"/>
上传器位于选项卡容器/选项卡面板/内容模板/更新面板中,更新模式设置为条件。我是ASP的新手,所以我不确定包含上传器的控件是否可能导致问题。
然后在我的代码中我有:
Dim filename As String = System.IO.Path.GetFileName(AsyncFileUpload2.FileName)
Dim comments As String = SpellTextBox1.Text
Dim NewDirectory As String = Server.MapPath("~/Helpdesk/UploadedFiles/" + TicketID.ToString())
Try
'Check if directory exists
If Not Directory.Exists(NewDirectory) Then
' Create the directory.
Directory.CreateDirectory(NewDirectory)
End If
AsyncFileUpload2.SaveAs(NewDirectory + "\" + filename)
Catch _ex As IOException
'Silently error for now
'Response.Write(_ex.Message)
End Try
在单击按钮后,或者从未存储
时,文件名似乎丢失了答案 0 :(得分:0)
解决方法:
Private Sub AsyncFileUpload1_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AsyncFileUpload1.UploadedComplete
If e.State = AjaxControlToolkit.AsyncFileUploadState.Success Then
Dim ticketID As String = Request.QueryString("ID").ToString()
Dim filename As String = e.FileName
Dim temp() As String = filename.Split("\")
filename = temp(temp.Length - 1)
Dim NewDirectory As String = Server.MapPath("~/Helpdesk/UploadedFiles/" + ticketID + "/")
'Check if directory exists
If Not Directory.Exists(NewDirectory) Then
' Create the directory.
Directory.CreateDirectory(NewDirectory)
End If
' Save the file on the server
AsyncFileUpload1.SaveAs(NewDirectory + filename)
'Now put the file details in the database
dbSaveFile(ticketID, filename, "UploadedFiles/" + ticketID + "/" + filename, "")
'Raise some kind of notification informing the user that this has been sucessfull
'And rebind the control
' Get Event Details and populate text fields
Dim dsFiles As DataSet = dbGetFiles(ticketID)
If dsFiles Is Nothing Then
' No need to error here if we have no files
Else
gvFiles.DataSource = dbGetFiles(ticketID)
gvFiles.DataBind()
End If
Else
' Do nothing
End If
End Sub