how to create a text file in asp.net MVC3 using c# -


i wanna ask how generate or create textfile, becuase want display data in database text.

im using c# in asp.net mvc 3

thank much! answer apreciated.

if want return data database in text file downloaded user's local computer, create action in controller in sample:

using system.io; using system.text;        public class somecontroller {      // action create text file 'your_file_name.txt' data     // string variable 'string_with_your_data', downloaded     // browser     public filestreamresult createfile() {         //todo: add data database string:         var string_with_your_data = "";          var bytearray = encoding.ascii.getbytes(string_with_your_data);         var stream = new memorystream(bytearray);          return file(stream, "text/plain", "your_file_name.txt");        }  } 

then can create actionlink action on view trigger file download:

@html.actionlink("download text file", "createfile", "somecontroller ") 

i hope helps!


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -