Microsoft KB Archive/810312

= How To Assign Local Resources to Image or Attachment Placeholders =

Article ID: 810312

Article Last Modified on 8/30/2004

-

APPLIES TO


 * Microsoft Content Management Server 2002

-





SUMMARY
The following code sample demonstrates how to create a posting by using a Publishing Application Programming Interface (PAPI) application (such as a Web service or a console application) that requires a file located on the file system to be assigned to an image placeholder or an attachment placeholder. public string CreatePosting(string UserID,                                    string Password,                                     string TemplateName,                                     string ChannelName,                                     string PostingName,                                     string NameOfImagePlaceholder,                                    string NameOfAttachmentPlaceholder,                                    string filename) {           // Create new MCMS application context. CmsApplicationContext cmsContext = new CmsApplicationContext;

// Authenticate against the new application context. // You also could use //     cmsContext.AuthenticateUsingUserHandle(, PublishingMode.Update) //     cmsContext.AuthenticateAsCurrentUser(PublishingMode.Update) cmsContext.AuthenticateAsUser(UserID,Password,PublishingMode.Update); // Retrieve the template with the name TemplateName. Template template = cmsContext.RootTemplateGallery.GetByRelativePath(TemplateName) as Template; if ( template == null ) {               return &quot;Could not find template &quot; + TemplateName + &quot;.&quot;; }           // Find the chosen channel to create your posting in. Channel channel = cmsContext.RootChannel.GetByRelativePath(ChannelName) as Channel; if ( channel == null ) {               return &quot;Could not find channel &quot; + ChannelName + &quot;.&quot;; }           if ( !channel.CanCreatePostings ) {               return &quot;Can not create postings in channel &quot; + channel.Path + &quot;.&quot;; }           // Create a new posting based on the template that you have specified. Posting newPosting = channel.CreatePosting( template ); // Set the name of the posting. newPosting.Name = PostingName; string URL = cmsContext.AcceptBinaryFile(filename);

// Set the contents of the AttachmentPlaceholder image. AttachmentPlaceholder attph = newPosting.Placeholders[NameOfAttachmentPlaceholder] as AttachmentPlaceholder; attph.Url = URL; attph.AttachmentText = URL;

// Set the contents of the ImagePlaceholder image. ImagePlaceholder imgph = newPosting.Placeholders[NameOfImagePlaceholder] as ImagePlaceholder; imgph.Src = URL;

newPosting.Submit;

// Do not forget to commit your changes back to CMS. cmsContext.CommitAll; // Return the GUID of the created posting. return newPosting.Guid; }

Keywords: kbhowto KB810312

-

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

© Microsoft Corporation. All rights reserved.