How To Assign Local Resources to Image or Attachment Placeholders

Article translations Article translations
Article ID: 810312 - View products that this article applies to.
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

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(<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;
}

Properties

Article ID: 810312 - Last Review: February 27, 2014 - Revision: 1.2
APPLIES TO
  • Microsoft Content Management Server 2002
Keywords: 
kbnosurvey kbarchive kbhowto KB810312

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com