问题描述:

i have an interactive aspx dialog with some address data (like name, email, address,...). Now i want the user to be able by clicking a button to download the address data as vcf file.

Now, generating the vcf compatible string isn't the problem. But saving it to the client is.

While it returns the vcf string just fine, it does not open a "Save AS"-dialog. Below i attached my logic for the file download.

What am i doing wrong?

(Maybe it's worth mentioning that the code-behind function calls come from java script,...)

Thanks for any helpfull answers in advance.

Public Sub SaveText(ByVal Text As String)

Dim FileName As String = System.IO.Path.GetRandomFileName()

Using sw As New System.IO.StreamWriter(Server.MapPath(FileName + ".txt"))

sw.WriteLine(Text)

sw.Close()

End Using

Dim fs As System.IO.FileStream = Nothing

fs = System.IO.File.Open(Server.MapPath(FileName + ".txt"), System.IO.FileMode.Open)

Dim btFile(fs.Length) As Byte

fs.Read(btFile, 0, fs.Length)

fs.Close()

With HttpContext.Current.Response

.Clear()

.Buffer = True

.Expires = 0

.AddHeader("Content-disposition", "attachment;filename=" + FileName)

.AddHeader("Content-Length", btFile.Length.ToString)

.ContentType = "application/octet-stream"

.BinaryWrite(btFile)

'.OutputStream.Write(btFile, 0, btFile.Length())

.Flush()

.End()

End With

End Sub

网友答案:

Ok, the problem was not the above mentioned logic itself. The way i handeled the response on the client side was just wrong. The calling java script function expected something else. I would elaborate in more detail, but this stuff here is so home grown and proprietary, it wouldn't make any sense. Cheers.

相关阅读:
Top