c# - Cannot get SaveFileDialog to work with my web page -
this question has answer here:
i'm trying add method uses link grid view gets file server in form of stream , prompts user save it. i've added system.windows.forms reference controller , added following method.
[httpget] [authorize] public void downloadassetstream(int assetid) { //gstream created server file. stream mystream = gstream; savefiledialog savefiledialog1 = new savefiledialog(); savefiledialog1.filter = "pdf files (*.pdf)|*.pdf|all files (*.*)|*.*"; savefiledialog1.filterindex = 2; savefiledialog1.restoredirectory = true; if (savefiledialog1.showdialog() == dialogresult.ok) { if ((mystream = savefiledialog1.openfile()) != null) { // write file stream. mystream.close(); } } } }
there no error when code hits line if (savefiledialog1
goes , dialog doesn't appear. missing?
you missing can't use windows controls in asp.net application. might work visual studio not in real world.
instead of trying open file dialog, send result stream, example using filestreamresult
:
return new filestreamresult(gstream, "application/pdf");
the second parameter content type, example i've used content type pdf files.
Comments
Post a Comment