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

Updating a cutom field in a Document Library uisng C#

$
0
0

I am trying to update a field that I added to a document library> below is the code. I know I have been successful using similar code to update a list library but this does not work for a document library. Can I please get some assistance with modifying the code below to update a document Library (li.text is a value that I get from a selected listbox

 using (SPSite docSite = new SPSite(SPContext.Current.Web.Url))
                            {
                                using (SPWeb doclstweb = docSite.OpenWeb())
                                {
                                    doclstweb.AllowUnsafeUpdates = true;
                                    SPList doclist = doclstweb.Lists["Documents"];
                                    SPQuery docQuery = new SPQuery();
                                    docQuery.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + li.Text + "</Value></Eq></Where>";
                                    // SPListItem doclistItem = doclist(docQuery);

                                    SPListItemCollection docboItems = doclist.GetItems(docQuery);
                                   
                                    foreach (SPListItem doclstitem in docboItems)
                                    {
                                        doclstitem["AddedToExtSite"] = "Yes";
                                        doclist.Update();
                                    }
                                    doclstweb.AllowUnsafeUpdates = false;

                                    lblMsg.Visible = true;
                                    lblMsg.Text = " - document title " + li.Text;
                                }
                            }


IPW


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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