0
votes

I'm working on Sitecore 6.6. I wan to get all the fields for a particular item.

I'm getting all the fields using this

FieldCollection fieldcollection = Sitecore.Context.Database.GetItem(Id, LanguageManager.GetLanguages(Sitecore.Context.Database).Where(i => i.CultureInfo.ToString() == Globallanguage).FirstOrDefault(), Sitecore.Data.Version.Latest).Fields;

And looping through each field and adding items to a list

    foreach (Field field in fieldcollection)
    {
        if(fields!=null)
        {
        .....
        }
    }

But after returning some fields it is throwing me an error

Object reference not set to an instance of an object. at Code.Pipeline.NotFoundRedirector.GetAllMappedUrls()

I wanted to know whether I'm using correct method to get all fields

1
Can you add the error you're getting?Trayek
Check my updates question @TrayekAjay A
Check log files for more details. Can you post the whole exception from there?Marek Musielak
And what is it that you're doing in the foreach loop? I assume it's not just an empty loop? Also, is it always on the same field you get this? Is there any exception in the logfiles?Trayek
I'm adding the rquired fields to a list, and binding them to a gridview @TrayekAjay A

1 Answers

0
votes

I have got all the fields by changing the version and adding getall() method

 FieldCollection fieldcollection = Sitecore.Context.Database.GetItem(TargetId, LanguageManager.GetLanguages(Sitecore.Context.Database).Where(i => i.CultureInfo.ToString() == Globallanguage).FirstOrDefault(), Sitecore.Context.Database.GetItem(TargetId).Version).Fields;        
 fieldcollection.ReadAll();

The loop goes as usual

   foreach (Field field in fieldcollection)
    {
        if(fields!=null)
        {
        .....
        }
    }