Avatar of rwallacej

asked on 

Customise response save message OR another method of saving file to hard drive


I'm trying to let user save a file to their hard drive so they can exchange it with others (and feel they "own" the file rather than have it on only server).

After trawing the internet I found the attached code. (frustrating there;s not the normal "SaveDialog" as in windows forms)

This works, however it presents the user with a confusing message, "Do you want to OPEN or SAVE this file". The user only ever wants to SAVE it.....its some serialized stuff that doesn't make any sense to user if OPENED, only makes sense to the ASP.net application.

So I'd like to customise the message to say "Where do you want to SAVE" OR have another method of saving to user drive.

Maybe there's a better way to do the saving part; if so which - code please rather than links I'd prefer. Its important user can pick where they want to save (whether it be to a USB, C:, network etc.)

Thanks in advance for help.
Dim strFileName As String = System.IO.Path.GetRandomFileName()
        Dim strFriendlyName As String = "Friendly.txt"
        Dim texttowrite As String = "Text to write"
        Using sw As New System.IO.StreamWriter(Server.MapPath("TextFiles/" + strFileName + ".xml"))
        End Using
        Dim fs As System.IO.FileStream = Nothing
        fs = System.IO.File.Open(Server.MapPath("TextFiles/" + strFileName + ".xml"), System.IO.FileMode.Open)
        Dim btFile(fs.Length) As Byte
        fs.Read(btFile, 0, fs.Length)
        With Response
            .AddHeader("Content-disposition", "attachment;filename=" & strFriendlyName)
            .ContentType = "application/octet-stream"
        End With

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon