Writing a JSON (or TXT) file in WPF C# -
i have been trying make sense of http://msdn.microsoft.com/en-us/library/sfezx97z.aspx uses savefiledialog, hard me understand. have following code:
fileinfo existingfile = new fileinfo("c:\\users\\cle1394\\desktop\\apple foreign tax payment sample layout proposed - sample data.xlsx"); consoleapplication2.program.exceldata data = consoleapplication2.program.getexceldata(existingfile); var json = new javascriptserializer().serialize(data);
how can output contents of json
.json
or .txt
file?
i let user either see link/ button click download/ save file location on computer, or, display save file dialog box can save file location on computer.
edit (to let op comment on parts not clear):
savefiledialog savefiledialog1 = new savefiledialog(); savefiledialog1.showdialog(); if(savefiledialog1.filename != "") { file.writealltext(savefiledialog1.filename,json); }
you looking this, then:
file.writealltext(@"c:\some\path\json.txt",json);
and note save file using utf8-encoding without byte order mark. if need bom, need use file.writealltext(path, content, enconding);
update - adding sample savefiledialog:
if(!string.isnullorempty(savefiledialog.filename)) { //savefiledialog.filename should contain full path //according documentation: http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filename.aspx file.writealltext(savefiledialog.filename,json); }
Comments
Post a Comment