I am trying to get the top lever site URL in my timer job. Right now, I am using SPContext.Current.Site.Url which is giving an error. Please let me know how do I get the top level Site URL being in a ListItem. I have the code as follows
if (item[new Guid(Fields.ThumbnailFieldId)] != null)
{
SPFieldUrlValue thumbnail = new SPFieldUrlValue(item[new Guid(Fields.ThumbnailFieldId)].ToString());
string tempURL = thumbnail.Url.Replace("http://intranet.swlstg-test.nhs.uk", SPContext.Current.Site.Url.ToString());
this.ThumbnailUrl = tempURL.ToString();
}
I have my newsitem is in the following I am trying to change the thumbnail.Url
to SPContext.current.site.url alternative.
public NewsItemForTimerJob(SPListItem item)
{
// Get item details
this.Title = item[SPBuiltInFieldId.Title].ToString();
this.StartDate = (DateTime)item[new Guid(Fields.StartDateFieldId)];
this.EndDate = (DateTime)item[new Guid(Fields.EndDateFieldId)];
this.ContentType = item.ContentType.Name;
this.Headline = item[new Guid(Fields.HeadlineFieldId)].ToString();
this.NewsBody = item[new Guid(Fields.MainBody)].ToString();
this.Location = SPHelper.GetTaxonomyFieldValue(item, new Guid(Fields.Location), ", ");
this.CategoryList = SPHelper.GetTaxonomyFieldValuesList(item, new Guid(Fields.NewsCategory));
this.TagList = SPHelper.GetTaxonomyFieldValuesList(item, new Guid(Fields.Tags));
this.Type = item.ContentTypeId.ToString().StartsWith(ContentTypes.NewsBase_ID, StringComparison.CurrentCultureIgnoreCase) ? NewsType.News : NewsType.Events;
// Construct the URLs needed
this.MoreUrl = string.Format("{0}{1}?lstId={2}&itmId={3}&m={4}&y={5}&ct={6}",
//item.ParentList.ParentWeb.Url,
item.ParentList.ParentWeb.ServerRelativeUrl.ToString(),
((Type == NewsType.News) ? PageConstants.NewsDetailPage_Url : PageConstants.EventDetailPage_Url),
item.ParentList.ID,
item.ID,
StartDate.Month,
StartDate.Year,
ContentType);
this.ArchiveBrowserUrl = string.Format("{0}{1}?m={2}&y={3}&ct={4}",
item.ParentList.ParentWeb.ServerRelativeUrl.ToString(),
((Type == NewsType.News) ? PageConstants.NewsTimelinePage_Url : PageConstants.EventsTimelinePage_Url),
StartDate.Month,
StartDate.Year,
ContentType);
// Get the image - if missing get 'no image'
if (item[new Guid(Fields.ThumbnailFieldId)] != null)
{
SPFieldUrlValue thumbnail = new SPFieldUrlValue(item[new Guid(Fields.ThumbnailFieldId)].ToString());
this.ThumbnailUrl = thumbnail.Url;
}
else
{
this.ThumbnailUrl = SPUtility.ConcatUrls(item.ParentList.ParentWeb.ServerRelativeUrl, CommonConstants.Default_Img_Url);
}
}