Azure table query to csv c# -


i'm trying write azure table storage query result .csv file , store locally on machine (temp fine). i'm able query without issue - display results in messagebox. i'm doing using c#. don't want use external application, call on powershell script if takes. ultimately, i'm trying download csv query csv file instead of azure tables storage more functionality. (sql server isn't option @ time - although understand make life easier)

        cloudstorageaccount storageaccount =         cloudstorageaccount.parse    ("defaultendpointsprotocol=https;accountname=mystorageaccountnamehere;accountkey=mytablekeyhere         cloudtableclient tableclient = storageaccount.createcloudtableclient();         cloudtable table = tableclient.gettablereference("telephonyissuelog");          var managerquery =  new tablequery<issueentity>().where(tablequery.generatefiltercondition("rowkey", querycomparisons.equal, "issues"));         system.io.file.writealltext(@"c:\temp\csv.csv", managerquery); 

i figured out: starting top

    using csvhelper;            if (string.isnullorempty(txtfirstn.text) || string.isnullorempty(txtlname.text) || string.isnullorempty(cbdirection.text) || string.isnullorempty(cbphonesystem.text) || string.isnullorempty(txtcustphone.text) || string.isnullorempty(txtmanager.text) || string.isnullorempty(txtprogram.text) || string.isnullorempty(cblocation.text) || string.isnullorempty(txtphonenumber.text) || string.isnullorempty(cbissue.text) || string.isnullorempty(cbphonesystem.text))         {             messagebox.show("please fill out whole form. thank you!");          }         else         {             cloudstorageaccount storageaccount =                cloudstorageaccount.parse("defaultendpointsprotocol=https;accountname=myaccountname;accountkey=my-account-key             cloudtableclient tableclient = storageaccount.createcloudtableclient();             cloudtable table = tableclient.gettablereference("telephonyissuelog");             //await command use here don't try go forward before verify table exists , error out.             //notice made function async.  c# annoying out when using async , await yeah have fun :d. -=chris             await table.createifnotexistsasync();             issueentity issuelog = new issueentity("issues", lblrandom.text);             issuelog.firstname = txtfirstn.text;             issuelog.lastname = txtlname.text;             issuelog.calldirection = cbdirection.text;             issuelog.custnumber = txtcustphone.text;             //issuelog.firstname = tbfirstname.text;             //issuelog.lastname = tblastname.text;             issuelog.location = cblocation.text;             issuelog.manager = txtmanager.text;             issuelog.phonenumber = txtphonenumber.text;             issuelog.phonesystem = cbphonesystem.text;             issuelog.primaryissue = cbissue.text;             issuelog.program = txtprogram.text;              tableoperation insertoperation = tableoperation.insert(issuelog);             table.execute(insertoperation); 

then, comes query , csv edit:

        //get cloud storage          cloudstorageaccount storageaccount =                cloudstorageaccount.parse("defaultendpointsprotocol=https;accountname=my-account-name;accountkey=my-account-key         cloudtableclient tableclient = storageaccount.createcloudtableclient();         cloudtable table = tableclient.gettablereference("telephonyissuelog"); 

worked charm!

        //initiate writer          var sw = new streamwriter(@"c:\programdata\n3rasupportnotifier\test.csv");          var writer = new csvwriter(sw);              tablequery<issueentity> query = new tablequery<issueentity>().where(tablequery.generatefiltercondition("partitionkey", querycomparisons.equal, "issues"));         //write each record csv             foreach (issueentity entity in table.executequery(query))             {             writer.writefield(entity.firstname);             writer.writefield(entity.lastname);             writer.writefield(entity.location);             writer.writefield(entity.manager);             writer.writefield(entity.partitionkey);             writer.writefield(entity.phonesystem);             writer.writefield(entity.primaryissue);             writer.writefield(entity.timestamp);             writer.nextrecord();             } 

Comments