Using SPFolder in custom WebService

Hi all,

I was wondering if someone could help me out on this. We are using SharePoint 2007 SDK in an attempt to copy an existing "Template Directory" via a custom web service. The web service is running on the same machine as SharePoint.

I have created a separate class library with a method that performs the SPFolder methods. The web service invokes this method, passing it the name it wants the copied directory to be called.

public static string CopyTemplateFolder(string _projectName, string _rootDir, string _templateDir)
{
// Get SP configuration information
string sharePointWebsite = ConfigurationManager.AppSettings["SharePointWebSite"].ToString();

// Set the return value
string url = string.Empty;


// Instantiate SharePoint website
SPWeb essaWeb = new SPSite(sharePointWebsite).OpenWeb();

try
{
if (essaWeb.GetFolder(_rootDir + _templateDir).Exists)
{
SPFolder copyFolder = essaWeb.GetFolder(_rootDir + _templateDir);
copyFolder.CopyTo(_rootDir + _projectName);

...........

.........
}
}
catch (Exception ex)
{
throw ex;
}

return url;

}

However, when I run the code I get the following error: “The security validation for this page is invalid”

What am I missing



Answer this question

Using SPFolder in custom WebService

  • h1

    Found the solution which would like to share with you....

    In this instance the the solution was to set the SPWeb "AllowUnsafeUpdates" property to true

    // Instantiate SharePoint website
    SPWeb essaWeb = new SPSite(sharePointWebsite).OpenWeb();
    essaWeb.AllowUnsafeUpdates = true;

    This is probably not a recommended course of action but I don't see an issue as this is an internal operation.

    If anyone has any ideas they would like to share please feel free. Thanks!


  • Using SPFolder in custom WebService