2010-01-24 9 views
0

je dois récupérer les valeurs d'une zone de texte riche d'un code list.My jusqu'à maintenant est la suivante ..dans Récupération zone de texte riche sharepoint

 ArrayList arCategory=new ArrayList();    
     SPList myList = myWeb.Lists["PList"]; 
     SPQuery myQuery = new SPQuery(); 
     myQuery.Query = "<OrderBy><FieldRef Name='ProgramID' Ascending="False"/></OrderBy>; 

      SPListItemCollection myItemCol = myList.GetItems(myQuery); 

      foreach (SPListItem myItem in myItemCol) 
      {     
       string strCatTxt = (string)myItem["Category"];--> 

// Catégorie est la colonne de texte multiligne riche

   arCategory.Add(strCatTxt); 
      } 

      for (int j = 0; j < arCategory.Count; j++) 
      { 
      Label lblCategory = new Label(); 
      lblCategory.Text=arCategory[j].Tostring(); ---->Getting exception 
      } 

Répondre

0

Le problème n'est pas ici SharePoint. Dans votre code, vous avez lblCategory.Text=arCategory[j].Tostring();

Si arCategory[j] est null, vous obtenez une exception lorsque vous appelez ToString() dessus.

Donc, fondamentalement, vous pouvez le fixer comme ceci:

for (int j = 0; j < arCategory.Count; j++) { 
    if (arCategory[j]!=null){ 
    Label lblCategory = new Label(); 
    lblCategory.Text=arCategory[j].Tostring(); ---->Getting exception 
    } 
} 

EDIT: Ou, bien sûr, vous pouvez ajouter un élément <Where>... dans votre requête et lire uniquement les valeurs des éléments qui ont catégorie différente de null . Cela rendra votre requête plus rapide!

+0

Merci n'a pas pensé à ça .. !!! –

Questions connexes