title: Use of SPSite and SPWeb in a custom Sharepoint web service
body: <p>I am current coding a custom web service for a Sharepoint 2010 site.  This code is designed to copy the contents of one folder to another on sharepoint.</p>
  
  <p>Currently, my code uses 'SPSite(SourceURL).openWeb()' to get access to an SPWeb object for the site.  However, my code crashes and gives me the following error</p>
  
  <blockquote>
    <p>The Web application at 'SourceURL' could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.</p>
  </blockquote>
  
  <p>In my code, SourceURL is the URL of the main site formatted as "<a href="https://sitename.com" rel="nofollow">https://sitename.com</a>".</p>
  
  <p>Thanks for any help,<br>
  Scott</p>
  
  <p>EDIT: Here is the method that causes the error:</p>
  
  <pre><code>public void CopyFolderContents(String sourceURL, String folderURL, String destinationURL)
      {
          using (SPWeb oWebsite = new SPSite(sourceURL).OpenWeb())
          {
              SPFolder oFolder = oWebsite.GetFolder(folderURL);
  
              //Create a list of all files (not folders) on the current level
              SPFileCollection collFile = oFolder.Files;
  
              //Copy all files on the current level to the target URL
              CopyToTarget(collFile, destinationURL);
  
              //Create a list of all folders on the current level
              SPFolderCollection collFolder = oFolder.SubFolders;
  
              //Copy each of the folders and all of their contents
              EnumerateFolders(collFolder, destinationURL);
  
          }
      }
  </code></pre>