Reputation: 1221
Within my SharePoint list I use a field to hold a url and text, this is not a custom field, but its a standard SharePoint hyperlink field, SPFieldUrl type. When I set the SpFieldUrl Description and Url properties and save it to my list, on rare occations my data is never saved. How does this happen? Below is a sample of my code.
PopulateListItem(listItem,candidate);
listItem.Update();
SPFieldUrlValue newCandidateUrl = new SPFieldUrlValue();
newCandidateUrl.Description = listItem["Title"].ToString() +" ,"+listItem["FirstName"].ToString();
newCandidateUrl.Url = ConfigurationManager.AppSettings["EditUrl"]+"?id="+listItem.ID.ToString();
listItem["FormLink"] = newCandidateUrl;
listItem.Update();
Upvotes: 0
Views: 237
Reputation: 65361
You may be getting an exception, for example if
listItem["Title"]
is Null, Then
listItem["Title"].ToString()
Will throw a nulll reference exception
Upvotes: 1