Thoughts on Mass Document Upload

by dan 27. April 2009 19:26

Every now and then former AxCMS.net developer training attendees are confronted with the task of mass document upload. In most cases this task comes with migration project finalization. This time it has been a member of A EINS IT GmbH, a brand new partner to the Axinom family that wanted to know how to do.

So, how do we realize mass document upload? In view of the large quantity of methods (namely WSS, WebDAV, etc..) I will dicuss something that ships with the AxCMS.net 8.5 Premium Template Project and fits me most: Doing mass document upload programmatically!

Everything we need to accomplish this task is inside the Create_PremiumSample Project. The base class used is the Axinom.AECMS.Import.DocumentImporter class. Inside the PremiumSampleApplication.cs we find the following method:

1:

2: public void ImportDocuments(string xmlDocumentName, string pathToDocuments)

3: {

4:     DocumentImporter documentImporter = new DocumentImporter(_cmsSite, _categoryTree, new AxUser(_defaultUser, "axinom"));

5:     MessageCollection messages = documentImporter.Import(

6:         Path.Combine(_createHomeDir, pathToDocuments),

7:         (xmlDocumentName.IndexOf(@":\") > 0) ?   xmlDocumentName : Path.Combine(_createHomeDir, @"Texts\" + xmlDocumentName));

8:     DisplayMessages(messages);

9: }

The first line of code instanciates an object of the DocumentImporter class, passing references to a cms site object, a category tree and an AxUser instance that the documents are created by. The parameter objects listed are created in the Init() method inside the CreateApplication.cs file:

1: public virtual void Init()

2: {

3:     _msConnectionManager = new ConnectionManager(new SqlDbFactory(), CMSConfigurationSettings.DBCONNSTRING);

4:     _lsConnectionManager = new ConnectionManager(new SqlDbFactory(), CMSConfigurationSettings.DBCONNSTRINGPROD);

5:     Configuration.ConnectionManager = _msConnectionManager;

6:     _cmsSite = new CmsSite();

7:     _cmsSite.FileName = _templatesHomeDir + @"\CmsSite.xml";

8:     _cmsSite.Load();

9:     _categoryTree = new CategoryTree();

10:     _categoryTree.Load(false);

11:     AxUserAdapter adapter = new AxUserAdapter();

12:     AxContext.CurrentUser = (AxUser)adapter.Load(_defaultUser);

13: }

The second line calls the DocumentImporter.Import() Method, which signature reads as follows:

1: public MessageCollection Import(string pathToDocuments, string xmlDocumentName);

The pathToDocument parameter points to the documents to upload, while the xmlDocumentName parameter is the path to an xml file that lists all documents (omitting the path and file extension) to upload. The Create_PremiumSample projects documents.xml file is listed below:

1: <Documents>

2:   <Document name="AxCMS_Features">

3:     <Properties>

4:       <Property name="Details" subName="Caption" value="Überblick über die Features des AxCMS.net" />

5:       ...

6:     </Properties>

7:     <Categories>

8:       <Category path="Categories/Documents/de" direction="Both" />

9:     </Categories>

10:   </Document>

11:   <Document name="AxCMS_Module">

12:     <Properties>

13:       <Property name="Details" subName="Caption" value="Überblick über die Module des AxCMS.net" />

14:       ...

15:     </Properties>

16:     <Categories>

17:       <Category path="Categories/Documents/de" direction="Both" />

18:     </Categories>

19:   </Document>

20:   ...

21: </Documents>

So: How to do your own mass document upload?

If it is only once that you need to upload documents to your projects you could (and should) edit the documents.xml file to fit your needs. Afterwards you start the document import via the commandline.

If mass document upload is a task that you are confronted with more often than you might think about using the AxCMS.net Premium Template Project code to create your own module or even your own win32 application totally outside the AxCMS.net environment.

Would be very interested in your ideas!

Best
Dan

Tags:

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Dan Wucherpfennig - AxCMS.net evangelist

Dan Wucherpfennig is an IT consultant employed at EDV-Partner (http://www.edvpartner.de), a Hamburg based system integration and consulting company. 

Having many years of experience in developing projects with AxCMS.net, Dan has been awarded as an AxConsultant during the AxDays 2008.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar