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();
}