title: MOSS 2007 -- Invalid URL Exception SPSite.OpenWeb(...)
body: <p>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.</p>
  
  <p>The Code:</p>
  
  <pre><code>  try
          {
              SPSite scheduleSiteCol = new SPSite(branchScheduleURL);
              lblError.Text += Environment.NewLine + "Site Collection URL: " + scheduleSiteCol.Url;
              SPWeb scheduleWeb = scheduleSiteCol.OpenWeb(branchScheduleURL.Replace(scheduleSiteCol.Url, "")); //&lt;--- 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;
          }
  </code></pre>
  
  <p>Note:<br>
  branchScheduleURL is actually the whole URL that includes the URL of the Web as well.</p>
  
  <p>The output + exception:</p>
  
  <blockquote>
    <p>Site Collection URL: <a href="https://ourSite.com/mocc" rel="nofollow noreferrer">https://ourSite.com/mocc</a> 
    <br>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)</p>
  </blockquote>
  
  <p>Note:<br><a href="https://ourSite.com/mocc/internal/scheduletool" rel="nofollow noreferrer">https://ourSite.com/mocc/internal/scheduletool</a> is the SPWeb I am trying to open.</p>
  
  <p>Am I missing something obvious?  Any help would be greatly appreciated.</p>
  
  <p>Thanks.</p>