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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -