Hi ,
I deployed my dot net project on sharepoint but it is not working there. I am unable to resolve the following error:
Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
WebTrackingTool.DBFiles.DBRepository.GetDueInvoices(String query) in C:\Project\WebTrackingTool\WebTrackingTool\DBFiles\DBRepository.cs:117
WebTrackingTool.TrackerView.DisplayReminder(DateTime dateTime) in C:\Project\WebTrackingTool\WebTrackingTool\Admin\TrackerView.aspx.cs:43
WebTrackingTool.TrackerView.Page_Load(Object sender, EventArgs e) in C:\Project\WebTrackingTool\WebTrackingTool\Admin\TrackerView.aspx.cs:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
My cs file:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebTrackingTool
{
public partial class TrackerView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GenerateColumns();
if (Session["Reminder"] == null || Session["Reminder"].ToString() == "")
DisplayReminder(Convert.ToDateTime(Session["LastLogin"]));
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridTracker.PageIndex = e.NewPageIndex;
GridTracker.DataSource = Session["TrackerData"] as DataTable; //get datasource (list or datatable)
GridTracker.DataBind(); //bind data
}
private void DisplayReminder(DateTime dateTime)
{
string RemMessage = String.Empty;
if (dateTime.Date < DateTime.Now.Date)
{
DBFiles.DBRepository repo = new DBFiles.DBRepository();
DataSet ds = repo.GetDueInvoices();
DataTable dt = ds.Tables["TrackerDetails"];
dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
Session["DueInvoices"] = dt;
if (dt.Rows.Count > 0)
RemMessage += "REMINDER!! Due date approaching. ";
DataSet ds1 = repo.GetApproachingInvoices();
DataTable dt1 = ds1.Tables["TrackerDetails"];
dt1.PrimaryKey = new DataColumn[] { dt1.Columns[0] };
Session["UpcomingInvoices"] = dt1;
if (dt1.Rows.Count > 0)
RemMessage += "REMINDER!! Invoice date approaching. ";
DataSet dsReceipts = repo.GetPendingReceipts();
DataTable dtReceipts = dsReceipts.Tables["TrackerDetails"];
dtReceipts.PrimaryKey = new DataColumn[] { dtReceipts.Columns[0] };
Session["PendingReceipts"] = dtReceipts;
if (dtReceipts.Rows.Count > 0)
RemMessage += " " + dtReceipts.Rows.Count + " Receipts Pending. "; ///Change the reminder message as required
DataSet dsIPN = repo.GetDueInvoices();
DataTable dtIPN = dsIPN.Tables["TrackerDetails"];
dtIPN.PrimaryKey = new DataColumn[] { dtIPN.Columns[0] };
Session["PendingIPN"] = dtIPN;
if (dtIPN.Rows.Count > 0)
RemMessage += " " + dtReceipts.Rows.Count + " IPN Pending. ";
if (RemMessage == String.Empty)
RemMessage = "No pending requests.";
string cleanMessage = RemMessage.Replace("'", "\'");
Page page = HttpContext.Current.CurrentHandler as Page;
string script = string.Format("alert('{0}');", cleanMessage);
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(page.GetType(), "alert", script, true /* addScriptTags */);
}
Session["Reminder"] = "Yes";
}
}
#region GridSorting
protected void GridTracker_Sorting(object sender, GridViewSortEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = Session["TrackerData"] as DataTable;
if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
GridTracker.DataSource = Session["TrackerData"];
GridTracker.DataBind();
}
}
private string GetSortDirection(string column)
{
// By default, set the sort direction to ascending.
string sortDirection = "ASC";
// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}
// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}
#endregion
#region GridBind
private string[] GridDataKey = new string[] { "ID", "CustomerID", "InvoiceNo", "IPN", "PayableTo", "PONo", "Status", "Acknowledgement", "Invoice ReceiptDate" };
private string[] GridColName = new string[] { "S. No.", "Customer ID", "Invoice No.", "IPN", "Payable To", "PO Num", "Status", "Acknowledgement", "Invoice Receipt Date" };
private void GenerateColumns()
{
for (int i = 0; i < GridDataKey.Count(); i++)
{
BoundField bfield = new BoundField();
bfield.DataField = GridDataKey[i];
bfield.HeaderText = GridColName[i];
bfield.SortExpression = GridDataKey[i];
GridTracker.Columns.Add(bfield);
}
HyperLinkField bCol = new HyperLinkField();
bCol.HeaderText = "View";
GridTracker.Columns.Add(bCol);
HyperLinkField bCol1 = new HyperLinkField();
bCol1.HeaderText = "Edit";
GridTracker.Columns.Add(bCol1);
HyperLinkField bCol2 = new HyperLinkField();
bCol2.HeaderText = "Print";
GridTracker.Columns.Add(bCol2);
}
protected void GridTracker_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink link = new HyperLink();
link.Text = "View";
link.NavigateUrl = "/WebTrackingTool/Admin/TrackerEdit.aspx?id=" + e.Row.Cells[0].Text + "&FormMode=View&Invoices=All";
e.Row.Cells[9].Controls.Add(link);
HyperLink link1 = new HyperLink();
link1.Text = "Edit";
link1.NavigateUrl = "~/Admin/TrackerEdit.aspx?id=" + e.Row.Cells[0].Text + "&FormMode=Edit";
e.Row.Cells[10].Controls.Add(link1);
HyperLink link2 = new HyperLink();
link2.Text = "Print";
link2.NavigateUrl = "~/Admin/Form.aspx?id=" + e.Row.Cells[0].Text;
e.Row.Cells[11].Controls.Add(link2);
}
}
private void LoadData()
{
DBFiles.DBRepository repo = new DBFiles.DBRepository();
DataSet ds = new DataSet();
//string year = DateTime.Now.Date.Year.ToString("yyyy");
//string month = DateTime.Now.Date.Month.ToString("MMM").ToLower();
string year = tbYear.Text;
string month = ddlMonth.SelectedItem.Text.Substring(0,3).ToLower();
if (month == string.Empty)
{ }
ds = repo.GetTracker("select * from TrackerDetails where LCase(Month) like '%" + month + "' And LCase(Month) like '" + year + "%'");
DataTable dt = ds.Tables["TrackerDetails"];
dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
Session["TrackerData"] = dt;
Session["Month"] = month;
Session["Year"] = year;
GridTracker.DataMember = "TrackerDetails";
GridTracker.DataSource = Session["TrackerData"];
GridTracker.DataBind();
}
#endregion
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("~/Admin/TrackerEdit.aspx?id=0&FormMode=Insert");
}
protected void btnLoad_Click(object sender, EventArgs e)
{
LoadData();
}
}
}
Here is my web.config file
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
<authorization>
<allow users="?"/>
</authorization>
<sessionState timeout="20"/>
</system.web>
<!--<location path="Admin">
<system.web>
<authorization>
<allow roles="Administrator"/>
<deny users="*"/>
</authorization>
</system.web>
</location>-->
<system.webServer/>
<connectionStrings>
<clear/>
<add name="TrackerConnectionString" connectionString="Data Source= ~\WebTrackingTool\Tracker.accdb Provider=Microsoft.ACE.OLEDB.12.0;" providerName="System.Data.OleDb"/>
<clear/>
</connectionStrings>
</configuration>