Is it possible to create a folder in a SharePoint list through a SmartObject?

  • 20 April 2009
  • 4 replies
  • 3 views

Badge +2

I am using SmartObjects to load process documents into a document library in SharePoint.  I am wondering if there is an easy way with a SmartObject to create the folder before uploading the document?  It does not seem to work just setting the folder name on the document creation, I assume it expects that the folder already exists.


I am fairly new to K2 so any help would be appreciated.


Thanks,


Jason


4 replies

Badge +6

Hi Jason,


a good way consists to use the Web Service Object (http://www.k2underground.com/k2/ProjectHome.aspx?ProjectID=45) to invoke the createFolder method from the DWS WSS/MOSS web service (http://msdn.microsoft.com/en-us/library/ms774480.aspx). Unfortunately, I faced recently a WSS/MOSS bug with these method:


In certain case, it can only create a folder into the default document library of the specified site and not on the docLib I use in parameter of the method.


So, for now, my recommendation is to create a very simple web-service creating a wss/moss folder (using WSS API) and after you can use it with a smartobject.


HTH

Badge +2

Thanks Jan,


This definitely lead me down the path.  I opted to use the SharePoint library and have put together the code as follows:



using

(SPSite siteCollection = new SPSite(VPApprovalForms.Properties.Settings.Default["MossURL"].ToString()))


{


siteCollection.AllowUnsafeUpdates =

true;


using (SPWeb site = siteCollection.AllWebs[VPApprovalForms.Properties.Settings.Default["SiteName"].ToString()])


{


site.AllowUnsafeUpdates =

true;


SPDocumentLibrary docLib = (SPDocumentLibrary)site.Lists[VPApprovalForms.Properties.Settings.Default["VPDocLibraryName"].ToString()];


SPFolderCollection folColl = site.Folders;


//NOTICE: String replace to switch '-' with '%2d' for the URL


folColl.Add(VPApprovalForms.Properties.

Settings.Default["VPDocLibraryURL"].ToString() + Page.Request.QueryString["VPApprovalID"].Replace("-", "%2d") + "/");


docLib.Update();


}



Have you tried anything similar to this or can you think of any issues this might cause?


Thanks,


Jason

Badge +11

Jason,


If this is going to be a web service, it will have to reside on the SharePoint server so it has access to the SharePoint API assemblies.  SharePoint already exposes many of its API capabilities as web services, so there is likely already an existing service you can use.


David


(long time no see)

Badge +2

I was able to get everything working as expected with the following code:


DocLibraryWS.

Dws dWorkspace = new VPApprovalForms.DocLibraryWS.Dws();


dWorkspace.Credentials = System.Net.

CredentialCache.DefaultCredentials;


folderURL = VPApprovalForms.Properties.

Settings.Default["VPDocLibraryName"] + "/" + processGUID;


result = dWorkspace.CreateFolder(folderURL);


 


Jason

Reply