Creating Sharepoint Doclib


Badge +3
:?:

Hey guys/gals,

I've searched the fora and can't find an answer, can someone please help with a newbie Q?

I'm trying to create a doclib on a sharepoint site and am struggling!! Its easy enough to create lists, list items etc but not doclibs. :roll:

Can I just "cobble" the code from the list to create a doclib, or would I have to write it from scratch?

Cheers,

Paulbean

11 replies

Badge +9
Do you want to create the DocLib using K2.net? The best would be to have a look at the SPS Object model documentation for samples on how to create a Doclib with code. That code can then be used in a Default Server Event.
Badge +3
:roll:

Many thanks Renier, I ssuppose I should've looked in the first place!?!

Cheers,
PaulBean
Badge +9
Nothing wrong with asking, if I had a sample of this I would have posted it, unfortunately I don t hence me pointing you to the SPS SDK. If anybody has done this and have samples available please post it as this can accelerate people in the future.

Paul when you figure it out please post some samples, I am sure we can all benefit out of your experience in this :D
Badge +6
Hi All,

Below is a code sample to create a folder in a SPS document library.
(Add the web reference to the SharePoint Document Workspace Service aka DWS to your web project. In my example it is referenced by 'Dws')

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 = "doclibrary/foldername";
string Result = oDWS.CreateFolder(Path);
}
catch (Exception ex)
{
throw ex;
}
finally
{
oDWS = null;
}
}

NB!! The K2.net Server service account must have appropriate rights in SPS

Have fun! :D
Badge +6
:oops:

Only noticed now that the K2SPSlist also has a method to create a folder in a document library.

Here is some VB code that can do the job using the K2SPSlist.asmx:

Sub Main(ByVal K2 As ServerEventContext)
K2.Synchronous = True
InvokeMethod(K2)
End Sub

Sub InvokeMethod(ByVal K2 As ServerEventContext)
Dim oAssembly As K2SPSList = New K2SPSList
Try
'SHAREPOINT
Dim sServer As String
Dim sSite As String
Dim sLibrary As String

sServer = K2.StringTable("MoveDocSite")
If Not sServer.EndsWith("/") Then sServer &= "/"

sSite = K2.StringTable("MoveDocWeb")
If Not sSite.EndsWith("/") And sSite.Trim <> "" Then sSite &= "/"

sLibrary = K2.StringTable("MoveDocArchivedLib")
If Not sLibrary.EndsWith("/") And sLibrary.Trim <> "" Then sLibrary &= "/"

'FOLDER NAMES
Dim dNow As System.DateTime = System.DateTime.now
Dim sMonth As String = dNow.Month()
Dim sYear As String = dNow.year()
Dim sDesURL As String
sMonth = right("0" & sMonth, 2) 'Convert 9 to 09
sDesURL = sLibrary & sYear

Dim SpsUtils As New SourceCode.K2SPUtilities.SPSUtilities
oAssembly.Url = sServer & "_vti_bin/K2SpsList.asmx"
oAssembly.Credentials = SpsUtils.GetCredentials(sServer)

'CREATE YEAR
Dim sResult As System.String
If Not oAssembly.CreateFolder(sSite, sDesURL , sResult) Then
Throw New Exception(sResult)
End If

'CREATE YEAR/MONTH
sDesURL &= "/" & sMonth
If Not oAssembly.CreateFolder(sSite, sDesURL , sResult) Then
Throw New Exception(sResult)
End If

K2.ActivityInstanceDestination.DataFields("MoveDocFolder").value = sDesURL 'Used by move

Catch ex As Exception
Throw ex
Finally
oAssembly = Nothing
End Try
End Sub
Badge +3
K2SPSList is the one to use (well, I found it the easiest way to create a folder!! :lol: )

Below is the code to create a folder within a sharepoint document library:-

public void Main(ref ServerEventContext K2) {


// Set up variables
string ErrorMessage = "";
string Site;
string Server;
string FolderName;

Server = "http://<Sharepoint Server>/";

if (! (Server.EndsWith("/"))) Server += "/";

Site = "<Site for folder>";

if (! (Site.EndsWith("/") && Site.Trim() != "" )) Site += "/";

FolderName = ("<Folder Name> " + K2.ProcessInstance.Folio.ToString());

K2SPSList SpsList = new K2SPSList();

// Set Url for Web Service
SpsList.Url = Server + "_vti_bin/K2SpsList.asmx";

SpsList.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Call Web Service to Create List Item
ErrorMessage = "";
if (! (SpsList.CreateFolder(Site, FolderName,
ref ErrorMessage) )) {
// Error Occurred in CreateFolder - Raise Error
throw new System.Exception(ErrorMessage);
}
}
Badge +3
Dear sir,

I think others have provided enough codes how to create a SPS Doc , we can use SPS SDK API, use SPS Web Service, etc. And also we can use K2.net Teamplate SDK to write our custom Template, we can use it just like sps list template cao do, it is easy to write one. I have finished a custom template to create sps area before.

Regards,
karon.
Badge +3
Good on yer!? :roll:
Badge +8
My app uses K2SpsList.CreateFolder in the first activity to create a folder to contain the xml schema and attached documents for this workflow instance.

In my last activity, I'm creating the same folder in a '/completed' folder, copying the documents to that folder, then deleting the files in the original folder.

All of this is working fine.

Now I'm trying to use DeleteFolder, which has exactly the same parameters as the CreateFolder method, to get rid of the original one, but it is failing and I can't figure out why.
The error message is: Value does not fall within the expected range.

Does anyone have a clue on this? I can't find anything on the forum about using DeleteFolder.
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

Hi all


(Add the web reference to the SharePoint Document Workspace Service aka DWS to your web project. In my example it is referenced by 'Dws').


sorry i can not add this dws webservice into my project as you show.


i can see it in the local  webservice list, but it displayed "the page can not not be found" when i click on it


please help me solve this problem


 


thanks in advances


 

Reply