Error: The security validation for this page is invalid. whe
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Error: The security validation for this page is invalid. whe

 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development
Author Message
gFunk
Guest





Posted: Tue Nov 01, 2005 5:51 pm    Post subject: Error: The security validation for this page is invalid. whe Reply with quote

I am trying write a WebMethod to copy a file from one document library
to another (regardless if it is in SPS or WSS). I get all the way
through the process up until i try to add the file to the files
collection of the folder of the destination library. Any help would be
greatly appreciated.

*there was quite a bit of trial and error so the code is a bit sloppy.


---- CODE ----

[WebMethod]
public string CopyDocumentFromAreaToSite(string SourceAreaURL, string
SourceDocumentLibrary, string SourceFilePath, string
DestinationSiteURL, string DestinationDocumentLibrary, string
DestinationFilePath)
{
SPWeb sourceWeb = GetWebFromFullURL(SourceAreaURL);
SPFile file = GetFile(sourceWeb, SourceDocumentLibrary,
SourceFilePath);

SPWeb destinationWeb = GetWebFromFullURL(DestinationSiteURL);
SPFolder destinationFolder = GetFolder(destinationWeb,
DestinationDocumentLibrary, DestinationFilePath);

destinationFolder.Files.Add(file.Name, file.OpenBinary(), true);

string ret = file.Name;
return ret;

}
private SPWeb GetWebFromFullURL(string FullURL)
{
SPSite site = new SPSite(FullURL);
SPWeb area;
int areaStartindex = site.Url.Length + 1;
if (FullURL.Length > areaStartindex)
{
string areaName = FullURL.Substring(site.Url.Length + 1);
area= site.AllWebs[areaName];
}
else
{
area = site.OpenWeb();
}

return area;

}

private SPFile GetFile(SPWeb Web, string DocumentLibrary, string
FilePath)
{
SPFolder folder = GetFolder(Web, DocumentLibrary, FilePath);

string fileName = FilePath.Substring(FilePath.LastIndexOf("/") + 1);
return folder.Files[fileName];
}

private SPFolder GetFolder(SPWeb Web, string DocumentLibrary, string
FilePath)
{
SPFolder folder = Web.Folders[DocumentLibrary];
int lastIndex = 0;
int nextIndex= FilePath.IndexOf("/", lastIndex + 1);
while (nextIndex > 0)
{

string folderName = FilePath.Substring(lastIndex + 1, nextIndex -
lastIndex - 1);
folder = folder.SubFolders[folderName];
lastIndex = nextIndex;
nextIndex = FilePath.IndexOf("/", lastIndex + 1);
}
return folder;
}
Back to top
gFunk
Guest





Posted: Tue Nov 01, 2005 9:51 pm    Post subject: Re: Error: The security validation for this page is invalid. Reply with quote

Ok, I got it to work. the key was to put my web service (along with
hard coded disco and wsdl files) into the _vti_bin directory in my
SharePoint website. I used the following article as reference.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/odc_writingcustomwebservicesforsppt.asp

As a side note: it is pretty inconvenient to have to go through all
this just to make a simple web service. I hope Microsoft improves
developer friendliness in the upcoming release.

gFunk
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB