-3

I want to write C# code to create new ledger in Tally database .I am developing an ERP using ASP.Net MVC . I want to integrate the application with Tally. So that the Ledger data would be transferred as XML format to the Tally. How to do this? I need all your valuable contributions.here is my code

string strGRNDate = "2/02/2014";
                string strVoucherNo = "3";
                string strGRNNo = "2";
                string strSupplierName = "Abhinav Sharma";
                string strPurchaseOrder = "2";
                string strGRN = "1";
                string strGRNValueNtv = "2";


                xmlstc = "<ENVELOPE>" + "\r\n";
                xmlstc = xmlstc + "<HEADER>" + "\r\n";
                xmlstc = xmlstc + "<TALLYREQUEST>Import Data</TALLYREQUEST>" + "\r\n";
                xmlstc = xmlstc + "</HEADER>" + "\r\n";
                xmlstc = xmlstc + "<BODY>" + "\r\n";
                xmlstc = xmlstc + "<IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REPORTNAME>Vouchers</REPORTNAME>" + "\r\n";
                xmlstc = xmlstc + "<STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "<SVCURRENTCOMPANY>##SVCURRENTCOMPANY</SVCURRENTCOMPANY>" + "\r\n";
                xmlstc = xmlstc + "</STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "<TALLYMESSAGE xmlns:UDF=" + "\"" + "TallyUDF" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<VOUCHER VCHTYPE=" + "\"" + "Purchase" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<DATE>" + strGRNDate + "</DATE>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERTYPENAME>Purchase</VOUCHERTYPENAME>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERNUMBER>" + strVoucherNo + "</VOUCHERNUMBER>" + "\r\n";
                xmlstc = xmlstc + "<REFERENCE>" + strGRNNo + "</REFERENCE>" + "\r\n";
                xmlstc = xmlstc + "<PARTYLEDGERNAME>" + strSupplierName + "</PARTYLEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<PARTYNAME>" + strSupplierName + "</PARTYNAME>" + "\r\n";
                xmlstc = xmlstc + "<EFFECTIVEDATE>" + strGRNDate + "</EFFECTIVEDATE>" + "\r\n";
                xmlstc = xmlstc + "<ISINVOICE>Yes</ISINVOICE>" + "\r\n";
                xmlstc = xmlstc + "<INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<BASICORDERDATE>" + strGRNDate + "</BASICORDERDATE>" + "\r\n";
                xmlstc = xmlstc + "<BASICPURCHASEORDERNO>" + strPurchaseOrder + "</BASICPURCHASEORDERNO>" + "\r\n";
                xmlstc = xmlstc + "</INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>" + strSupplierName + "</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>Yes</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "<BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "<NAME>" + strGRNNo + "</NAME>" + "\r\n";
                xmlstc = xmlstc + "<BILLCREDITPERIOD>30 Days</BILLCREDITPERIOD>" + "\r\n";
                xmlstc = xmlstc + "<BILLTYPE>New Ref</BILLTYPE>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>Abhinav Sharma</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>No</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRNValueNtv + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "</VOUCHER>" + "\r\n";
                xmlstc = xmlstc + "</TALLYMESSAGE>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "</IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "</BODY>" + "\r\n";
                xmlstc = xmlstc + "</ENVELOPE>" + "\r\n";

                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:" + Connection.TallyPort);
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentLength = xmlstc.Length;
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
                streamWriter.Write(xmlstc);
                streamWriter.Close();
                string result;
                HttpWebResponse objResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }

I am getting error at every spot

tereško
  • 58,060
  • 25
  • 98
  • 150
Aapkanigam
  • 13
  • 1
  • 4
  • 1
    If you need our _valuable contributions_, show your effort first. Be more specific about your problem. Put your work. – Soner Gönül Dec 08 '14 at 12:12

1 Answers1

2

dear you have not initialize strings .declare xml string as string .moreover you can change connection.tally port to 9000 .here is the final code .

 string strGRNDate = "2/02/2014";
                string strVoucherNo = "3";
                string strGRNNo = "2";
                string strSupplierName = "Abhinav Sharma";
                string strPurchaseOrder = "2";
                string strGRN = "1";
                string strGRNValueNtv = "2";


                string xmlstc = "<ENVELOPE>" + "\r\n";
                xmlstc = xmlstc + "<HEADER>" + "\r\n";
                xmlstc = xmlstc + "<TALLYREQUEST>Import Data</TALLYREQUEST>" + "\r\n";
                xmlstc = xmlstc + "</HEADER>" + "\r\n";
                xmlstc = xmlstc + "<BODY>" + "\r\n";
                xmlstc = xmlstc + "<IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REPORTNAME>Vouchers</REPORTNAME>" + "\r\n";
                xmlstc = xmlstc + "<STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "<SVCURRENTCOMPANY>##SVCURRENTCOMPANY</SVCURRENTCOMPANY>" + "\r\n";
                xmlstc = xmlstc + "</STATICVARIABLES>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDESC>" + "\r\n";
                xmlstc = xmlstc + "<REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "<TALLYMESSAGE xmlns:UDF=" + "\"" + "TallyUDF" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<VOUCHER VCHTYPE=" + "\"" + "Purchase" + "\" >" + "\r\n";
                xmlstc = xmlstc + "<DATE>" + strGRNDate + "</DATE>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERTYPENAME>Purchase</VOUCHERTYPENAME>" + "\r\n";
                xmlstc = xmlstc + "<VOUCHERNUMBER>" + strVoucherNo + "</VOUCHERNUMBER>" + "\r\n";
                xmlstc = xmlstc + "<REFERENCE>" + strGRNNo + "</REFERENCE>" + "\r\n";
                xmlstc = xmlstc + "<PARTYLEDGERNAME>" + strSupplierName + "</PARTYLEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<PARTYNAME>" + strSupplierName + "</PARTYNAME>" + "\r\n";
                xmlstc = xmlstc + "<EFFECTIVEDATE>" + strGRNDate + "</EFFECTIVEDATE>" + "\r\n";
                xmlstc = xmlstc + "<ISINVOICE>Yes</ISINVOICE>" + "\r\n";
                xmlstc = xmlstc + "<INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<BASICORDERDATE>" + strGRNDate + "</BASICORDERDATE>" + "\r\n";
                xmlstc = xmlstc + "<BASICPURCHASEORDERNO>" + strPurchaseOrder + "</BASICPURCHASEORDERNO>" + "\r\n";
                xmlstc = xmlstc + "</INVOICEORDERLIST.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>" + strSupplierName + "</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>Yes</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "<BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "<NAME>" + strGRNNo + "</NAME>" + "\r\n";
                xmlstc = xmlstc + "<BILLCREDITPERIOD>30 Days</BILLCREDITPERIOD>" + "\r\n";
                xmlstc = xmlstc + "<BILLTYPE>New Ref</BILLTYPE>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRN + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</BILLALLOCATIONS.LIST>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERNAME>Abhinav Sharma</LEDGERNAME>" + "\r\n";
                xmlstc = xmlstc + "<GSTCLASS/>" + "\r\n";
                xmlstc = xmlstc + "<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>" + "\r\n";
                xmlstc = xmlstc + "<LEDGERFROMITEM>No</LEDGERFROMITEM>" + "\r\n";
                xmlstc = xmlstc + "<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>" + "\r\n";
                xmlstc = xmlstc + "<ISPARTYLEDGER>No</ISPARTYLEDGER>" + "\r\n";
                xmlstc = xmlstc + "<AMOUNT>" + strGRNValueNtv + "</AMOUNT>" + "\r\n";
                xmlstc = xmlstc + "</ALLLEDGERENTRIES.LIST>" + "\r\n";
                xmlstc = xmlstc + "</VOUCHER>" + "\r\n";
                xmlstc = xmlstc + "</TALLYMESSAGE>" + "\r\n";
                xmlstc = xmlstc + "</REQUESTDATA>" + "\r\n";
                xmlstc = xmlstc + "</IMPORTDATA>" + "\r\n";
                xmlstc = xmlstc + "</BODY>" + "\r\n";
                xmlstc = xmlstc + "</ENVELOPE>" + "\r\n";

                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:" + 9000);
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentLength = xmlstc.Length;
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
                streamWriter.Write(xmlstc);
                streamWriter.Close();
                string result;
                HttpWebResponse objResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }
  • getting error Voucher totals do not match! 1: Voucher totals do not match! Dr: Cr: 3.00 Cr Diff: 3.00 Cr 0 0 0 0 0 0 1 – Dinesh Rabara Sep 17 '15 at 08:29
  • Hi Ashish, Will you please help us how can I get ledger list for a particular company? As, I've many company in my tally and each company have different ledger. I need to get ledger list company wise. – dilipkumar1007 Mar 16 '17 at 07:56