spslist.CreateFolder, spslist.DeleteFolder

  • 11 April 2007
  • 3 replies
  • 1 view

Badge +8
In our process, the first activity after submitting the infopath form is to create a sharepoint folder and upload the xml file into it. We also upload any file attachments to that folder.

During the lifetime of the workflow instance (which may be years, but more often is several months) this folder is used to view documents associated with the workflow, including an updated version of the xml each time the form is updated.

In the last activity of the workflow, when the process instance is completed, we are trying to move the folder that was created into a folder named 'Completed' at the same heirarchical level.

I'm using CreateFolder in the first activity, then again in the last event of the last activity to first create the working folder, then the completed folder then the subfolder (named the same as the working folder).


If Not SpsList.CreateFolder(Site, Division & "Completed", ErrMsg) Then
Console.WriteLine("------- Could not create folder " & Division & "Completed due to the following error:" & ErrMsg)
Else
Console.WriteLine("------- Folder " & Division & "Completed Created.")
End If

If Not SpsList.CreateFolder(Site, Division & "Completed/" & Folder, ErrMsg) Then
Console.WriteLine("------- Could not create folder " & Division & "Completed/" & Folder & " due to the following error:" & ErrMsg)
Else
Console.WriteLine("------- folder " & Division & "Completed/" & Folder & " Created.")
End If



Then I loop thru the files in the working folder, copying each one to the folder under 'Completed/' of the same name, finally deleting it from the source folder:


For Each sFile In spsList.GetFolderFiles(Server, Site, Division & Folder, ErrMsg)
If sFile = "" Then Goto NextFile
If Not spsList.UpLoadDocument (Server, Site, Division & "Completed/" & Folder, sFile, oByte, True, ErrMsg) Then
Console.WriteLine("------- Could not upload document due to the following error:" & ErrMsg)
Else
'delete file
If Not spsList.DeleteDocument(Site, Division & Folder, sfile, ErrMsg) Then
Console.WriteLine("------- Could not delete the document due to the following error:" & ErrMsg)
Else
Console.WriteLine("------- File " & Division & Folder & "/" & sFile & " deleted ...")
End If
End If
NextFile:
Next


All of this works fine, and at this point the source folder is empty.

Now comes the problem: The DeleteFolder method has the same arguments as the CreateFolder method, so I follow the above code with:

If Not spsList.DeleteFolder(Site, Division & Folder, ErrMsg) Then
Console.WriteLine("------- Could not delete folder " & Site & Division & Folder & " due to the following error:" & ErrMsg)
Else
Console.WriteLine("------- Folder " & Division & Folder & " deleted ...")
End If


I invariably get the error "Value does not fall within the expected range."

I'm at a dead end - can anyone help on this?

3 replies

Badge +6
I could not get the K2SPSList.DeleteFolder to work either.

I did get the DWS.DeleteFolder working though.

Here is the code for it. (It is very similar to the code above to create a folder...)

public void Main(ServerEventContext K2)
{
K2.Synchronous = true;

Dws oDWS = new Dws();
try
{
// Set Url for Web Service
// Remember that the site where the folder is to be created must
//be added to the normal url of the web service.
// In this case it was 'sites/eccentrix'
oDWS.Url = "http://eccent:81/sites/Eccentrix/_vti_bin/DWS.asmx";

// Set Credentials
oDWS.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Call Web Service to 'foldername' create folder in
//'doclibrary' document library
string Path = "DocLibName/FolderName";
string Result = oDWS.DeleteFolder(Path);
}
catch (Exception ex)
{
throw ex;
}
finally
{
oDWS = null;
}
}

HTH,
Conrad
Badge +8
Thanks, Conrad. I was beginning to think that no one else had tried this.

It is now working fine.
Badge +6
Glad to be of help :-)

Reply