Microsoft KB Archive/327750

= How to use an MCMS Web service to import multiple items into the resource gallery =

Article ID: 327750

Article Last Modified on 5/6/2005

-

APPLIES TO


 * Microsoft Content Management Server 2002

-



This article was previously published under Q327750



SUMMARY
You can use the Web Author to administer resource gallery items in Microsoft Content Management Server (MCMS) 2002. However, if you must add multiple items to the resource gallery, this may be inconvenient. This article describes how to create a MCMS Web service to perform bulk imports of resources into the resource gallery.



MORE INFORMATION
The following sample Web service shows how to import multiple resources into the gallery. Note that the sample is not a ready-to-use solution, although it will work in most scenarios. The sample only focuses on the functionality and does not include error handling routines. You can adjust the sample to your specific environment.

To create the MCMS Web service, follow these steps:

 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. In the New Project dialog box, expand Content Management Server Projects under Project Types, and then select Visual C# Projects. Under Templates, click MCMS Web Service to create the project. On the File menu, point to Add New Item. Under Categories, expand Web Project Items, and then select Code. Under Templates, click Web Service to add a new Web service to your project.  In the new .asmx file, switch to Code view. Replace the existing code with the following: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Security.Principal; using System.IO; using Microsoft.ContentManagement.Publishing;

namespace ResourceManager {   ///     /// Summary description for AddResources. ///    public class AddResources : System.Web.Services.WebService {       public AddResources {           //CODEGEN: This call is required by the ASP.NET Web Services Designer. InitializeComponent; }

#region Component Designer generated code //Required by the Web Services Designer. private IContainer components = null; ///        /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///        private void InitializeComponent {       }

///        /// Clean up any resources being used. ///        protected override void Dispose( bool disposing ) {           if(disposing && components != null) {               components.Dispose; }           base.Dispose(disposing); }       #endregion

[WebMethod] public string DoAddResources(string ResourceGalleryPath, string PathContainingResource) {           // Get the MCMS application context. CmsApplicationContext cmsContext = new CmsApplicationContext;

// Logon to MCMS: // Assumes that you have Windows Authentication turned on. WindowsIdentity ident = HttpContext.Current.User.Identity as WindowsIdentity; // Make sure to set the context to Update mode (which means you can write            // back to MCMS using PAPI). cmsContext.AuthenticateUsingUserHandle(ident.Token.ToInt32,PublishingMode.Update);

ResourceGallery rsg = cmsContext.Searches.GetByPath(ResourceGalleryPath) as ResourceGallery;

//Import all items in a particular directory. DirectoryInfo dir = new DirectoryInfo( PathContainingResource ); int i=0; foreach(FileSystemInfo fsi in dir.GetFileSystemInfos) {               FileInfo f = (FileInfo)fsi; rsg.CreateResource(f.FullName); i++; }

// Commit changes back to MCMS. cmsContext.CommitAll; return i.ToString+&quot; Items added to the resource gallery &quot;+ResourceGalleryPath; }   } }                    </li> Build the solution.</li> Open the Internet Service Manager (ISM) and disable anonymous access for the virtual directory that contains the new Web service. You must do this because the service will access the MCMS database with the account of the currently connected user, and the currently connected user must be an MCMS administrator.</li> Open Microsoft Internet Explorer and use the following URL to open the Web service location (note that you must substitute  and   with the names in your project):

http://localhost/ / .asmx

</li> In the browser, click the DoAddResource method.</li> In the first input field, type the destination path in the resource gallery. This resource gallery must already exist. The path that is specified is the same as the path that is shown in the Site Deployment Manager. The path must be an absolute path and must start with &quot;/Resources/&quot;. For example, to add resource gallery items to the Sample Small Business Gallery, specify /Resources/Sample/Small Business.</li> In the second input field, specify the source directory where the items that you want to import to the database are located.

NOTE: All files in this directory will be uploaded to the database. This directory must be located on the Web server computer. If it is not, delegation issues may occur.</li></ol>

Additional query words: bulk import

Keywords: kbhowto kbfix KB327750

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.