[英]“Save As” Dialog in ASP.Net for exporting an excel file? (service account)
I have a code working for saving the exported file into my PC/Destination however since the ASP.NET (4.0) will be displayed in a server running a service account, i would like to let the user after he clicks the button1 to prompt "Save as" dialog so they can save it in their respective folder ( In the user's PC, not server ). 我有一个代码可用于将导出的文件保存到PC /目的地,但是由于ASP.NET(4.0)将显示在运行服务帐户的服务器中,因此我希望在用户单击button1后提示用户“另存为”对话框,以便他们可以将其保存在各自的文件夹中( 在用户的PC中,而不是服务器中 )。 (i can not use environment since it will grab the service account address, since this is in the server its not possible.)
(我无法使用环境,因为它将获取服务帐户地址,因为这在服务器中是不可能的。)
Note: to get the user name i'm using request.servervariables("Logon_User") and did look for some posts here. 注意:要获取用户名,我正在使用request.servervariables(“ Logon_User”)并在此处查找了一些帖子。 - Exporting datatable to excel file with save dialog - Export DataGridView To Excel with Save Dialog?
- 使用保存对话框 将数据表 导出到excel文件中-使用保存对话框 将DataGridView导出到Excel? - Dialog Box for Save As location in VBA Macro
-VBA宏中“另存为”位置对话框
Dim cnn As SqlConnection
Dim connectionString As String
Dim sql As String
Dim i, j As Integer
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
connectionString = "Data Source=xxxx"
cnn = New SqlConnection(connectionString)
cnn.Open()
sql = "SELECT * FROM ControlCharts"
Dim dscmd As New SqlDataAdapter(sql, cnn)
Dim ds As New DataSet
dscmd.Fill(ds)
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
xlWorkSheet.Cells(i + 1, j + 1) = _
ds.Tables(0).Rows(i).Item(j)
Next
Next
'here instead of saving it to the C drive, let the user choose.
xlWorkSheet.SaveAs("C:\\ControlCharts.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
cnn.Close()
CheckBox1.Checked = False
You cannot have the user interact with UI and filesystem on the server. 您不能让用户与服务器上的UI和文件系统进行交互。
Instead, you can save the file to a temporary path on the server, then serve it as a file download over HTTP. 相反,您可以将文件保存到服务器上的临时路径,然后将其用作通过HTTP下载的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.