Trying To Insert xml data in Tally(Units of measure) Using C#

936 Views Asked by At

Trying To Insert xml data in Tally(Units of measure) Using C# I have an harcoded value to which I convert into the xml format , and trying to Insert xml data Into the Tally which having http://localhost:9000.I inserted data to Tally for ledger creation but failed for Units of measure from Inventory Info.

Xml Data :

String xmlstc = "";
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>All Masters</REPORTNAME>\r\n";
xmlstc = xmlstc + "<STATICVARIABLES><SVCURRENTCOMPANY>Siddharth</SVCURRENTCOMPANY></STATICVARIABLES>\r\n";
xmlstc = xmlstc + "</REQUESTDESC>\r\n";
xmlstc = xmlstc + "<REQUESTDATA>\r\n";
xmlstc = xmlstc + "<TALLYMESSAGE xmlns:UDF=" + "\"" + "TallyUDF" + "\">\r\n";
xmlstc = xmlstc + "<UNIT NAME=" + "\"" + "Kg" + "\" Action =" + "\"" + "Create" + "\">\r\n";
xmlstc = xmlstc + "<NAME>" + "Kg" + "</NAME>\r\n";               
xmlstc = xmlstc + "<ORIGINALNAME>" + "Kilogram" + "</ORIGINALNAME>\r\n";           
xmlstc = xmlstc + "<ISUPDATINGTARGETID>" + "No" + "</ISUPDATINGTARGETID>\r\n";
xmlstc = xmlstc + "<ASORIGINAL>" + "Yes" + "</ASORIGINAL>\r\n";
xmlstc = xmlstc + "<ISGSTEXCLUDED>" + "No" + "</ISGSTEXCLUDED>\r\n";
xmlstc = xmlstc + "<ISSIMPLEUNIT>" + "Yes" + "</ISSIMPLEUNIT>\r\n";
xmlstc = xmlstc + "<ALTERID>" + "1326" + "</ALTERID>\r\n";
xmlstc = xmlstc + "<DECIMALPLACES>" + "1" + "</DECIMALPLACES>\r\n";
xmlstc = xmlstc + "</UNIT>\r\n";
xmlstc = xmlstc + "</TALLYMESSAGE>\r\n";
xmlstc = xmlstc + "</REQUESTDATA>\r\n";
xmlstc = xmlstc + "</IMPORTDATA>\r\n";
xmlstc = xmlstc + "</BODY>";
xmlstc = xmlstc + "</ENVELOPE>";

Code to send data in Tally (Inventory Info => Units Of measure)

String lTallyLocalHost = "http://localhost:9000";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(lTallyLocalHost);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = (long)xmlstc.Length;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter lStrmWritr = new StreamWriter(httpWebRequest.GetRequestStream());
lStrmWritr.Write(xmlstc);
lStrmWritr.Close();
HttpWebResponse lhttpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream lreceiveStream = lhttpResponse.GetResponseStream();
StreamReader lStreamReader = new StreamReader(lreceiveStream, Encoding.UTF8);
lResponseStr = lStreamReader.ReadToEnd();
lhttpResponse.Close();
lStreamReader.Close();
1

There are 1 best solutions below

0
On

Download Tally connector Library and add reference to your project Now you can Interact with tally without using XML in your code

To create Unit in Tally use below code

Using TallyConnector //Importing TallyConnector Library
using TallyConnector.Models;

Ctally = new Tally();

Unit NewUnit = new Unit();
NewUnit.Name = "Kg";
NewUnit.OriginalName = "Kg";
NewUnit.DecimalPlaces= 1;

await Ctally.PostUnit(NewUnit);// Creates Unit in Tally