-4

The error is: Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments

I have no idea why this is happening, please bare in mind that I'm very new to C# and don't exactly understand how to work with it yet. I'm trying to get the file to retrieve a column from a database table and insert it into a CSV file with extra headers. The database table is cmsDictionary and the column is key, this should populate the CSV key column and the others should be blank to be populated by the user which will then be imported into the cmsLanguageText table.

//This is my controller file which is throwing the error.

using UmbracoImportExportPlugin.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Text;
using Umbraco.Core.Persistence;
using Umbraco.Web;
using Umbraco.Web.WebApi;
using System.Data;
using System.Data.SqlClient;

namespace UmbracoImportExportPlugin.App_Code
{
    public class ExportDictionaryAllController : UmbracoAuthorizedApiController
    {

        [System.Web.Http.AcceptVerbs("GET", "POST")]
        public static void ExportAll(List<Item> DictionaryItems)
        {
            getList(List<Item> DictionaryItems);
            string attachment = "attachment; filename= DictionaryItems.csv";
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("Content-Disposition", attachment);
            HttpContext.Current.Response.ContentType = "text/csv";
            HttpContext.Current.Response.AddHeader("Pragma", "public");
            WriteColumnName();
            foreach (Item item in DictionaryItems)
            {
                WriteItemInfo(item);
            }
            HttpContext.Current.Response.End();
        }

        private static void WriteItemInfo(Item item)
        {
            StringBuilder sb = new StringBuilder();
            AddComma(item.Key, sb);
            AddComma(item.English, sb);
            AddComma(item.Hebrew, sb);
            AddComma(item.Russian, sb);
            HttpContext.Current.Response.Write(sb.ToString());
            HttpContext.Current.Response.Write(Environment.NewLine);
        }

        private static void AddComma(string value, StringBuilder sb)
        {
            sb.Append(value.Replace(',', ' '));
            sb.Append(", ");
        }

        private static void WriteColumnName()
        {
            string columnNames = "Key, English, Hebrew, Russian";
            HttpContext.Current.Response.Write(columnNames);
            HttpContext.Current.Response.Write(Environment.NewLine);
        }

        public List<String> getList(List<Item> DictionaryItems)
        {
            UmbracoDatabase db = ApplicationContext.DatabaseContext.Database;
            var select = new Sql("SELECT key FROM cmsDictionary");
            List<Item> DictionaryItems = db.Fetch<Item>(select);
            return DictionaryItems;
        }
    }
}
  • 1
    Does this compile? – janhartmann Apr 20 '16 at 08:52
  • At which line does the error occur? – MakePeaceGreatAgain Apr 20 '16 at 08:53
  • 2
    @janhartmann I doubt it! See `getList(List DictionaryItems);` for example! – RB. Apr 20 '16 at 08:53
  • It doesn't compile, it's a compilation error. however when I change `getList(List DictionaryItems);` to `getList(DictionaryItems);` I receive the following error: **An object reference is required for the non-static field, method, or property 'UmbracoImportExportPlugin.App_Code.ExportDictionaryAllController.getList(System.Collections.Generic.List)** – Jonathan Yaniv Ben Avraham Apr 20 '16 at 08:56
  • That's because you are trying to call a non static method inside a static method. Either make a new instance of the class or mark the getList method as static. Also you're not using the return value. – Mo Hasan Apr 20 '16 at 08:59
  • I don't understand what people mean by the return value, can somebody tell me what I have to return, and if I have to return it in `getList()` or whether I have to return it in `ExportAll()`? – Jonathan Yaniv Ben Avraham Apr 20 '16 at 09:03
  • 1 do not use [System.Web.Http.AcceptVerbs("GET", "POST")] GET and POST on same method, better to make different http methods for different verbs. 2 getList(List DictionaryItems) method is not static so u cant call it from static method here 3- getList(List DictionaryItems); should be called like getList(DictionaryItems); – Rajdeep Apr 20 '16 at 09:03

2 Answers2

2

Well, this line seems wrong:

getList(List<Item> DictionaryItems);

Should be:

getList(DictionaryItems);

The compiler error should give you a line in the code file where the error is.

Paddy
  • 33,309
  • 15
  • 79
  • 114
-1

Use this as your method definition:

public static List<String> getList(List<Item> DictionaryItems) 
{ 
  UmbracoDatabase db = ApplicationContext.DatabaseContext.Database; 
  var select = new Sql("SELECT key FROM cmsDictionary"); 
  List<string> DictionaryItems = db.Fetch<Item>(select); 
  return DictionaryItems; 
}
zx485
  • 28,498
  • 28
  • 50
  • 59