Saving/Downloading file
-
Hello, I am trying to create a web application where the client has the option to save a file onto his computer (with his permission), but I haven't been able to find a solution for that problem. I suspect it might be impossible for security reasons. If that can't be done, I would like to save the file on the server, but still allow the client a SaveFileDialog to choose the location on the server, and I haven't been able to find a solution for that too. I'd appreciate any help, Alex.:confused:
-
Hello, I am trying to create a web application where the client has the option to save a file onto his computer (with his permission), but I haven't been able to find a solution for that problem. I suspect it might be impossible for security reasons. If that can't be done, I would like to save the file on the server, but still allow the client a SaveFileDialog to choose the location on the server, and I haven't been able to find a solution for that too. I'd appreciate any help, Alex.:confused:
Why can't you just send a file into the Client Browser? Save the file into the server and then just do Response.Redirect(filename); In the client browser will display, Open/Save/Cancel dialog box. Or you can do this, this is an example in PDF, make sure you change the type for different file formats:
string sFile = "sample.pdf"; Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "Application/pdf"; try { Response.WriteFile( MapPath( sFile ) ); Response.Flush(); Response.Close(); } catch { Response.ClearContent(); }
-
Why can't you just send a file into the Client Browser? Save the file into the server and then just do Response.Redirect(filename); In the client browser will display, Open/Save/Cancel dialog box. Or you can do this, this is an example in PDF, make sure you change the type for different file formats:
string sFile = "sample.pdf"; Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "Application/pdf"; try { Response.WriteFile( MapPath( sFile ) ); Response.Flush(); Response.Close(); } catch { Response.ClearContent(); }
Thanks, but I found a better way to do this using javascript:
string script = ""; script += ""; script += "function save() { "; script += "window_handle = window.open('"+filename+"','something');"; script += "window_handle.document.execCommand(\"SaveAs\");"; script += "window_handle.close(); }"; script += "save();"; script += ""; Page.RegisterClientScriptBlock("anything",script);
Alex.