I believe K2SPSList is an internal (as in K2 product) component that was never intended to be a public API; thus there is no documentation that I am aware of.
However, you can see many examples of its use if you use the various K2.net 2003 SharePoint event templates within K2.net Studio and then Generate and Edit the code.
I have managed to generate code to delete a file using the wizard. I now need to get a list of all files in a folder so that I can iterate through them - not sure how to get this working.
the delete code works fine:
SpsList.DeleteDocument(site, folder, file, ref errorMsg);
finding the files doesnt work:
foreach(object file in SpsList.GetFolderFiles(server, site, folder, ref errorMsg)) { // do stuff }
This should be really simple, just not sure what I'm doing worng. And I haven't been able to generate any wizard code to do something similar to see how to correctly call the function. Any help very much appreciated.
Hi ETP
Why don't you try and generate web service references in visual studio to get an idea of what the web methods look like that you're trying to use then you can import the code into K2?
Good luck with your project!
Tim
Hi etp,
GetFolderFiles returns a string array of the file names within the folder so there's no need to do a foreach until after you get the array.
Try this, where "http://portal" is the name of my portal root url and "sites/claims" is the relative path from the portal root. Claim Documents is the name of the document library I want to query.
K2SPSList SpsList = new K2SPSList();
// Set Url for Web Service
SpsList.Url = Server + "_vti_bin/K2SpsList.asmx";
// Set Credentials
SourceCode.K2SPUtilities.SPSUtilities SpsUtils = new SourceCode.K2SPUtilities.SPSUtilities();
SpsList.Credentials = SpsUtils.GetCredentials(Server);
string error = "";
string b] files;
files = SpsList.GetFolderFiles("http://portal","sites/claims","Claim Documents",ref error);
// now you have a string array containg all the files.
-mike
Thanks Mike. I'm not sure what is going here. I worked out that the code returned a string array and the code is fine, but the GetFolderFiles method is returning null (the string array is not being initiliased). I have an identical piece of code in another event that works fine. I can only think that there must be something different in the set up of these 2 events, do you know of any event specific setting (like a permissions setting or something) that might stop the method returning the file list? I am really stumped.
Can you verify for me that all files have the SharePoint "Title" metadata property filled out? Also, I made the assumption that we were talking about SharePoint 2003, is that correct?
-mike
Hi Mike, well typically I managed to get something working almost immediately after my last post
The problem was that the file I am searching contains both files and subfolders. It doesnt find a document name for the subfolders, so when I tried to loop through the array I got a null object error. So the bug was that I had an array containing null objects which I confused for a null array. Unfortunately debugging in the K2 studio is not the easiest process!
Many thanks for you help.
My pleasure. Typically I find it much easier to write all custom code in little test harness desktop application and than cut and paste into your server events. You can also attach to your custom code running in server events using Visual Studio if you like by attaching to that process.
Good luck,
-mike
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.