Hi,
I have two projects in my solution, one for console app and another for a web app. I need to re-use some code from the console app in my web app. I've pasted classes from my console app into my web app as links.
These are the methods I have in my web app:
namespace Export
{
public partial class XeroExport
{
public async Task Call_BalanceSheet(DateTime reportDate, int entityID, DateTime periodStart, DateTime periodEnd, AccountingApi apiInstance, string xeroTenantId, string accessToken, string connectDB, string dataDB)
{
...
}
}
}
namespace Export
{
public partial class XeroExport
{
public async Task Xero_Connect(string clientId, string clientSecret, int entityID)
{
...
}
...
}
...
}
Below is what I have in my web app project. I need to call the following methods:
Cleanup
Call_BalanceSheet
XeroExport
I am getting errors like: "Error CS0103 The name 'Cleanup' does not exist in the current context WebReports C:\...\WebReports\ReportsSelection.aspx.cs 109 Active"
namespace WebReports
{
public partial class ReportsSelection : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String reportName = ReportName.SelectedItem.Value;
...
RunSelectedReport(reportDate, reportName, entityID, await Xero_Connect(clientId, clientSecret, entityID), tenantId);
}
public void RunSelectedReport(DateTime reportDate, string reportName,int entityId, AccountingApi apiInstance, string xeroTenantId)
{
if (reportName == "Balance Sheet")
{
Cleanup(null, null, entityId, "[dbo].[myTable]", dataDB);
Call_BalanceSheet(reportDate, entityId, startDate, endDate, apiInstance, xeroTenantId, accessToken, connectDB, dataDB);
}
}
...
}
}
namespace Export
{
public partial class XeroExport: ApiWrapper
{
public void DBExport(DateTime reportDate, int entityId, AccountingApi apiInstance, string xeroTenantId)
{
...
}
public void Cleanup(Nullable periodStart, Nullable periodEnd, int entityId, String tableName, String dataDB)
{
...
}
}
}
Any ideas?
Thanks.
Sachin SinghPosted May 29, 2022, 9:45 AM
1. In the web app, please click add-reference ->Projects-> Choose the console app.
2. Please add the using statement at the top of the code inside web form code-behind
3. now consume the console app class as
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var res=Program.AnyConsoleMethod();
}
}
}
}
Note:- Program is the class name in the console app and the method is static.
Roustam AkhmetovPosted May 29, 2022, 9:01 AM
Sachin SinghPosted May 29, 2022, 6:21 AM