Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Get SharePoint file field value in visual web part

$
0
0
Hi, I'm trying to retrieve the value of the Comments column in a document library but all I can get is the field name. This is my code...
... can you help me please?using (SPSite site = new SPSite(url))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            BoundField bfield = new BoundField();
                            SPList list = web.Lists[List];
                            SPView view = list.Views[View];
                            SPListItemCollection items = list.GetItems(view);
                            SPFolder RootFolder = list.RootFolder;
                            string myComments = "";
                            foreach (SPFile file in RootFolder.Files)
                            {

                                if (file.Item.Fields.ContainsField("Comments"))
                                {
                                    myComments = file.Item.Fields["Comments"].ToString();
                                }

                                string fileUrl = file.Item[SPBuiltInFieldId.EncodedAbsUrl] as string;
                                sb.AppendLine("<li>");
                                sb.AppendLine("<h3><a href='" + fileUrl + ">");
                                sb.AppendLine(file.Title);
                                sb.AppendLine("</a></h3>");
                                sb.AppendLine("<p>");
                                sb.AppendLine(myComments);
                                sb.AppendLine("<br/>");
                                sb.AppendLine(file.Name);
                                sb.AppendLine("</p>");
                                sb.AppendLine("</li>");
                            }


                        }

                    }


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>