How To Assign Local Resources to Image or Attachment Placeholders

This article has been archived. It is offered "as is" and will no longer be updated.
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(<handle>, 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 "Could not find template " + TemplateName + ".";			} 			// Find the chosen channel to create your posting in.			Channel channel = cmsContext.RootChannel.GetByRelativePath(ChannelName) as Channel;			if ( channel == null )			{				return "Could not find channel " + ChannelName + ".";			} 			if ( !channel.CanCreatePostings )			{				return "Can not create postings in channel " + channel.Path + ".";			} 			// 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;}

Article ID: 810312 - Last Review: 02/27/2014 18:42:59 - Revision: 1.2

Microsoft Content Management Server 2002

  • kbnosurvey kbarchive kbhowto KB810312