我遇到了问题,我花了很多时间寻找解决方案,但我的答案还不错。问题是我试图使用“savefiledialog”,当我在我的电脑的本地主机上运行它完美的工作时,对话框出现任何问题,我能够保存文件,因为它假设工作...但是当我在iis服务器上发布它并尝试使用它时,它没有出现,我的意思是没有出现对话框savefile,我放了一个Try Catch,但它没有发送任何错误消息,我不知道问题出在哪里,我希望有人对所发生的事情有所了解。在此先感谢,我的代码是:
受保护的子Button1_Click(发件人为对象,e为System.EventArgs)处理Button1.Click
Dim _newThread As New Threading.Thread(AddressOf Descarga)
_newThread.SetApartmentState(ApartmentState.STA)
_newThread.Start("C:\Compras\Prueba.txt")
End Sub
Private Sub Descarga(ByVal _ruta As Object)
Dim Dialog As New System.Windows.Forms.SaveFileDialog
Dialog.InitialDirectory = "C:\"
Dialog.Title = "Save text Files"
Dialog.CheckFileExists = True
Dialog.CheckPathExists = True
Dialog.DefaultExt = "txt"
Dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
Dialog.FilterIndex = 2
Dialog.RestoreDirectory = True
If Dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
FileCopy(_ruta, Dialog.FileName)
End If
End Sub
答案 0 :(得分:0)
您正在使用Windows窗体SaveFileDialog。当您执行ShowDialog时,它将在服务器上打开它,而不是在客户端浏览器中打开它。
您需要将文件作为回复发送到客户端。
修改强>
这样的事情应该提示客户端保存文件:
Dim FileName As String = "Prueba.txt"
Dim FilePath As String = "C:\Compras\"
Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
response.ClearContent()
response.Clear()
response.ContentType = "text/plain"
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";")
response.TransmitFile(FilePath + FileName)
response.Flush()
response.End()