Filename of Excel file

The following code

exldoc.Save(String.Format("Export_{0}.xls", DateTime.Now.ToShortDateString), FileFormatType.Default, Aspose.Cells.SaveType.OpenInExcel, Response)

produces a download dialogue where the Name property takes the name of the abc.aspx file. I'd like to be able to chose the filename my self.

The code is in the code behind of a user control which is embeded in the abc.aspx file.

Do I need to change some NTFS rights? If yes, which folder: that of the user control or that of the aspx file

I'm using Cells v3.7.2.0

It seems that's a problem of your IIS or IE.

You can use the following code to verify it's a problem specific to your environment.

Dim fs1 As FileStream = New FileStream("d:\book1.xls",FileMode.Open,FileAccess.Read)
Dim data1() As Byte = New Byte(fs1.Length) {}
fs1.Read(data1, 0, data1.Length)


Me.Response.ContentType = "application/xls"
Response.AddHeader("content-disposition","attachment; filename=book1.xls")
Response.BinaryWrite(data1)
Response.End()

Please try to update your windows system to the latest patch.

What are the indications my system is sick/ok

Running the above code produces a download window with the filename ok.

In which event you call Excel.Save method? You can try to move the code to Page_Load event.

If you still cannot figure it out, you can try the following sample code:

Dim ms as MemoryStream = new MemoryStream()

excel.Save(ms, FileFormatType.Default)

Dim data1() As Byte = ms.ToArray()

Me.Response.ContentType = "application/xls"
Response.AddHeader("content-disposition","attachment; filename=book1.xls")
Response.BinaryWrite(data1)
Response.End()

Your code works fine. Both in page load in aspx and ascx file.

Here is my code:

Private Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click

Dim sql As String = "select * from orders"

Dim db As Database = DatabaseFactory.CreateDatabase
Dim cmd As DBCommandWrapper = db.GetSqlStringCommandWrapper(sql)
Dim ds As DataSet = db.ExecuteDataSet(cmd)

If hlpDatabase.ContainsData(ds, 0) Then
Dim aexc As New classAsposeCellsImportDataSets
aexc.Init()
aexc.Dataset = ds
Dim exldoc As Aspose.Cells.Excel = aexc.Execute()
exldoc.Save(String.Format("Export_{0}.xls", DateTime.Now.ToShortDateString), _
FileFormatType.Default, Aspose.Cells.SaveType.OpenInExcel, Response)
End If

What if you call Excel.Save method in page_load event?

Since my sample code works for you, you can use it.

As I know, this problem happens in some machine. When installed windows patch, it disappears. Maybe it's caused by that Aspose.Cells change some headers in Response object.

It seems to be a case of placing the code in the button_onclick event and not the page_load event.