c# - Xamarin StreamWriter -
could hep me doubt have?
i have embedded resource text file, , when try use streamwriter write on it, error: "a system.argumentexception thrown. can not write stream."
this code:
var assembly = assembly.getexecutingassembly(); var resourcename = "supermimo2.products.txt"; using (stream stream = assembly.getmanifestresourcestream(resourcename)) using (streamwriter writer = new streamwriter(stream)) {     writer.writeline(txtlines.text); }   could tell me can do?
thanks attention!
android , ios packages/bundles signed , not writable. write file, have use 1 of appropriate file system folders provided os.
for ios, refer guide:
http://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/
for android, can do
var path = environment.getfolderpath(environment.specialfolder.applicationdata); var filename = path.combine(path, my_file_name);   if want include file app , write it, first need include asset in app's bundle. need copy writable folder in order make changes it.
// read data asset using (streamreader sr = new streamreader (assets.open ("read_asset.txt")))     {         content = sr.readtoend ();     }  // writable file path var path = environment.getfolderpath(environment.specialfolder.applicationdata); var filename = path.combine(path, "write_asset.txt");  // write data writable path - can read , write file.writealltext(filename, content);      
Comments
Post a Comment