0

I'm currently trying to make a new Umbraco document, then request into query a string Rid and run my code (which will find the id of the page and display correctly hopefully) but I'm not able to call the reference request while it is a asp.net user control. I get the error An Object reference is required for the non-static field, method or property "System.Web.Ui.UserControl.Request.get"

the error comes from (request isn't recognised)

 Document rDoc = new Document(Convert.ToInt32(Request.QueryString["rid"]));

Any ideas? Code is below. If there's any improvements you could think / any reasons why this code wouldn't work, explanations are very much appreciated, thanks.

My includes include...

<%@Import Namespace="System.Net" %>
<%@Import Namespace="Newtonsoft.Json" %>
<%@Import Namespace="System.Web"%>
<%@Import Namespace="System.Web.Script.Serialization"%>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.ComponentModel" %>


<%--Umbraco Includes--%>
<%@ Import Namespace="umbraco.cms.businesslogic" %>
<%@ Import Namespace="umbraco.cms.businesslogic.web" %>
<%@ Import Namespace="umbraco.cms.businesslogic.member" %>


  static void Main(string[] args)
        {

            //Hashtable sqlDatatypeholder = new Hashtable();
            Dictionary<string, string> sqlDatatypeholder = new Dictionary<string, string>();
            DataTable tempTable = new DataTable();
            string SheetToPopulate = "";

            //Sql Connection      
            string _mySqlUrl = "sqlurl;";

            string _mySqlQuery = "query;";

            Document rDoc = new Document(Convert.ToInt32(Request.QueryString["rid"]));

            SqlConnection conn = new SqlConnection(_mySqlUrl);

            using (conn)
            {
                SqlCommand command = new SqlCommand(_mySqlQuery, conn);
                conn.Open();

                SqlDataReader reader = command.ExecuteReader();
                DataTable schemaTable = reader.GetSchemaTable(); //stores datatypes from sql
                tempTable.Load(reader); //stores data rows from sql
                reader.Close();

                //we need at least two date datatype fields for the sheet to be viewed in Gantt Chart view (smartsheet API rule), so everytime the date format is found, set to DATE

                if (tempTable != null && tempTable.Rows.Count > 0)
                {
                    foreach (DataRow row in schemaTable.Rows)
                    {
                        sqlDatatypeholder.Add(row["ColumnName"].ToString(), row["DataTypeName"].ToString());
                    }

                }
                else
                {
                    Console.WriteLine("Connection Open - No rows found.");
                    Console.ReadLine();
                }
            }
            SheetToPopulate = CreateSmartSheetFromDictionary(HashtableToDictionary(sqlDatatypeholder), tempTable);

            // Console.WriteLine(SheetToPopulate);
            PopulateSmartSheetRows(SheetToPopulate, tempTable);
            // Console.WriteLine("Sheet Populated");
            //Console.ReadLine();
        }
stmcallister
  • 1,682
  • 1
  • 12
  • 21
Alex
  • 673
  • 3
  • 9
  • 22
  • 1
    You are inside a static method and is trying to access an instance property(non-static) from there. – Mat J Apr 02 '14 at 11:20
  • I changed the main method to protected void Page_Load(object sender, EventArgs e) instead of the static method, how else would I go about fixing this? – Alex Apr 02 '14 at 12:22
  • That is a perfectly valid way. If `Page_Load` is event handler for `Load` event of the page (as I infer from the signature) and that is what you want, you can go with it. – Mat J Apr 02 '14 at 12:29
  • the reference for request still can't be found even inside the page_load. Any ideas? – Alex Apr 02 '14 at 12:44
  • Can you tell me the class in which this code resides and its base class. Are you sure it has `Request` property? – Mat J Apr 02 '14 at 13:00

0 Answers0