This may seem a bit trivial, but I have not been able to figure it out. I am opening up a SPSite and then trying to open up a SPWeb under that SPSite. This is working fine on the VPC, which has the same Site Collection/Site hierarchy, but on production, I get an exception telling me that the URL is invalid when I try the SPSite.OpenWeb(webUrl);. I have verified that the URL’s are correct.
The Code:
try
{
SPSite scheduleSiteCol = new SPSite(branchScheduleURL);
lblError.Text += Environment.NewLine + "Site Collection URL: " + scheduleSiteCol.Url;
SPWeb scheduleWeb = scheduleSiteCol.OpenWeb(branchScheduleURL.Replace(scheduleSiteCol.Url, "")); //<--- Throws error on this line
SPList scheduleList = scheduleWeb.GetList(branchScheduleURL + "/lists/" + SPContext.Current.List.Title);
return scheduleList.GetItemById(int.Parse(testID));
}
catch (System.Exception ex)
{
lblError.Text += Environment.NewLine + ex.ToString();
return null;
}
Note:
branchScheduleURL is actually the whole URL that includes the URL of the Web as well.
The output + exception:
Site Collection URL: https://ourSite.com/mocc
System.ArgumentException: Invalid URL: /internal/scheduletool. at Microsoft.SharePoint.SPSite.OpenWeb(String strUrl, Boolean requireExactUrl) at Microsoft.SharePoint.SPSite.OpenWeb(String strUrl) at MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.GetConflictListItem(String branchScheduleURL, String testID)System.NullReferenceException: Object reference not set to an instance of an object. at MOCCBranchScheduleListWeb.MOCCBranchScheduleListV3.CheckForConflicts(String[] cfcFlags1, DateTime startTime, DateTime endTime, String[] cfcFlags2)
Note:
https://ourSite.com/mocc/internal/scheduletool is the SPWeb I am trying to open.
Am I missing something obvious? Any help would be greatly appreciated.
Thanks.