How to query value of a field in document type

giang le asked on April 18, 2014 01:43

Hello! As subject, I have a question : How to retrieve value of a field on a document type by document Guid or alias path in code behind. ex: Get value of field "FAQQuestion" when know document Guid of a question using document type CMS.FAQ. Thank Giang

Correct Answer

Joel Dahlin answered on April 18, 2014 14:39

Something like this:

TreeNode doc = DocumentHelper.GetDocument([look at the right one for you]); string yourField = ValidationHelper.GetString(doc.GetValue("[column name]"), string.Empty);

0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on April 18, 2014 22:03

You can also use DataQuery which is new in v8. Take a look here at the article.

0 votesVote for this answer Mark as a Correct answer

giang le answered on April 22, 2014 03:34

Thank you for reply! I used your solution and i got value of a field in document type but i have a problem.

My code in webpart A:

var tr = new TreeProvider();
                var xxxGuid = new Guid("ac6f95f3-7275-481c-a5ef-045c7bd0d02b");
                var xxx= PageInfoProvider.GetPageInfo(xxxGuid);
                var doc = DocumentHelper.GetDocument(xxx.DocumentID, tr);
                var editContentValue = CMS.GlobalHelper.ValidationHelper.GetString(doc.GetValue("EditContent"), string.Empty);
                var currentPage = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, string.Empty, CMSContext.CurrentDocumentCulture.CultureCode, string.Empty, CMSContext.CurrentPageInfo.NodeID, true);
                currentPage.EditableRegions[yyy.ID.ToLower()] = CMS.GlobalHelper.ValidationHelper.GetString(editContentValue, string.Empty);
                currentPage.EditableRegions[zzz.ID.ToLower()] = CMS.GlobalHelper.ValidationHelper.GetString(Constants.zzzTitle, string.Empty);

TreeNode tn = tr.SelectSingleNode(CMSContext.CurrentDocument.DocumentID);

// Update the content XML
tn.SetValue("DocumentContent", currentPage.DocumentContent);

// Update the document

When I drag a webpart to old page,i work correct.But when create a new page then drag this webpart, i got a error "Object reference not set to an instance of an object." in line tn.SetValue("DocumentContent", currentPage.DocumentContent); Please help me resolve this problem!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.