AjaxControlToolkit 异步文件上传器无法正常工作
我的页面上有一个 AsynchFileUpload ,由于某种原因,当我尝试使用它将文件保存到服务器时,它失败了。
该控件允许我在本地选择一个文件,并在其文本框中显示本地文件路径,但是当我单击页面上的按钮时,我将使用该按钮提交所有详细信息,然后上传页面,一切都会出错我从 AsynchFileUploader 收到空引用异常。
我的上传器相当基本,看起来像:
<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
单击按钮后,文件名似乎在某处丢失,或者从未存储
I have an AsynchFileUpload on my page and for some reason when I try to use it to save the file to the server it falls.
The control will allow me to select a file locally and it displays the local file path in its text box, BUT when I then click a button on my page which I am going to be using to submit all details then upload the page everything goes wrong and I get a Null Ref Exception from the AsynchFileUploader.
My uploader is fairly basic and looks like:
<cc1:AsyncFileUpload runat="server"
ID="AsyncFileUpload2"
Enabled="true"
Visible="true"/>
The uploader is within a tab container / tab panel / content template / update panel with the update mode set to conditional. Im fairly new to ASP so im not sure if the controls containing the uploader could be causing the problem.
Then in my code i have:
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
It seems that the filename is being lost somewhere after the button is clicked, or just never stored
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过执行以下操作解决:
Solved by doing: