c# - System.IO.File is a type not a namespace -


im tring create file using system.io.file namespace howeever im using on mvc witch im new , error when publish proyect "a using namespace directive can applied namespaces; 'system.io.file' type not namespace"

this using statement:

using system; using system.reflection; using system.data; using system.collections.generic; using system.linq; using system.web; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using newtonsoft.json; using system.collections; using system.componentmodel; using system.data; using system.io; using system.io.file; using system.text;  using (var reader = system.io.file.createtext(@"c:\inetpub\wwwroot\procedimiento.txt"))             {                 // starting outer json array                 reader.writeline("[");                  (var rowindex = 0; rowindex < mytable.rows.count; rowindex++)                 {                     var row = mytable.rows[rowindex];                     var rowvalues = new list<string>(); // can reused if needed                     foreach (datacolumn column in mytable.columns)                         rowvalues.add(row[column].tostring());                      var jsonrow = jsonconvert.serializeobject(rowvalues);                      // write current row                     reader.write(jsonrow);                      // add separating comma                     if (rowindex != mytable.rows.count - 1)                         reader.writeline(",");                 }                  // end outer json array                 reader.writeline("]");             } 

the using keyword have different semantics depending on located.

when put directly in file it's tell namespaces import. in context can not have using statement class directly. well. can, syntax different. msdn.

the other usage dispose object when goes out of scope. in case can enter qualified class name (namespace + class name) or class name. msdn

in code have mixed two.

alternative 1

completely remove using statement in file , specify full class name in statement.

using system.web; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using newtonsoft.json; using system.collections; using system.componentmodel; using system.data; using system.text;  //in method using (var reader = system.io.file.createtext(@"c:\inetpub\wwwroot\procedimiento.txt")) 

alternative 2

remove namespace statement , class name directive:

using system.web; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using newtonsoft.json; using system.collections; using system.componentmodel; using system.data; using system.io; using system.text;  //in method using (var reader = file.createtext(@"c:\inetpub\wwwroot\procedimiento.txt")) 

alternative 3

rename class using directive. typically use when compiler can't distinguish between different identifiers (like having same class name in different imported namespaces).

using system.web; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using newtonsoft.json; using system.collections; using system.componentmodel; using system.data; using system.io; using iofile = system.io.file; //this using system.text;  //in method using (var reader = iofile.createtext(@"c:\inetpub\wwwroot\procedimiento.txt")) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -