-1

我有一个问题,我花了很多时间寻找解决方案,但我没有很好的答案。问题是我正在尝试使用“savefiledialog”,当我在我的电脑的本地主机中运行它时,它运行良好,对话框出现没有任何问题,我可以保存文件,因为它应该可以工作...但是当我在iis服务器上发布它并尝试使用它时,它没有出现,我的意思是对话框保存文件没有出现,我放了一个Try Catch,但它没有给我发送任何错误留言,我不知道问题出在哪里,希望有人对正在发生的事情有所了解。在此先感谢,我的代码是:

Protected Sub Button1_Click(sender As Object, e As 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 
4

1 回答 1

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()
于 2012-09-12T22:52:24.027 回答