Create news under the MOSS website

Source: Internet
Author: User
The principle of the MOSS News Center is different from that of the normal notification list. Every piece of news in MOSS news is a page, and Pages are stored in the Pages document library of the website.

Create news manually
Website operations: select the create page

The following page is displayed: (click the image to view the clear image)

Enter the corresponding content in the input box, and select "article page containing images on the left" in the page layout"
Click "CREATE" to create a blank news page. In the text box of the page, enter the news title and other content, and click "publish" to add a news item. You can also use the process for news publishing.

Program Creation news
Previously, we used to create news manually. Sometimes we need to use a program to publish news. For example, if there is an article for approval in the actual application, after multiple approvals, if the leader chooses to publish the news to the website, then we need to use the program to publish the article content as news. After talking a lot, what should we do?
First, we need to reference the following assembly, which can be found in the following directory: C: \ Program Files \ Common Files \ Microsoft Shared \ web server extensions \ 12 \ ISAPI
Microsoft. SharePoint. dll
Microsoft. sharepoint. portal. dll
Microsoft. SharePoint. Publishing. dll

Program code:

Using Microsoft. SharePoint;
Using Microsoft. SharePoint. Publishing;

// Some code for publishing news. Others are omitted.
//......

SPSite site = new SPSite ("siteUrl ");
SPWeb web = null;
PublishingSite pubsite = null;
PublishingWeb pubweb = null;


Try
{
// Get the PublishingWeb
Web = site. OpenWeb ("/"); // top-level website
// Pubsite = new PublishingSite (site );
Pubweb = PublishingWeb. GetPublishingWeb (web );

// The ID here is the content type corresponding to the page layout "(Article Page) article page with images on the left" when we manually created the previous step.
// There is a corresponding content type in the page layout for storing data.
SPContentTypeId articleContentTypeID = new SPContentTypeId ("batch ");

// Obtain the page layout of the article page containing images on the left of the Article Page
PageLayout [] layouts = pubweb. GetAvailablePageLayouts (articleContentTypeID );
PageLayout articlePageLayout = layouts [PageLayoutIndex];

// Generate the file name of the news page
String pageName = DateTime. Now. ToString ("yyyyMMdd-HHmmss ");

// Create a news page
PublishingPage newpage = pubweb. GetPublishingPages (). Add (pageName + ". aspx", articlePageLayout );
Newpage. ListItem ["title"] = "this is the news title ";
Newpage. ListItem ["author"] = "author ";
Newpage. ListItem ["page content"] = "this is the content of the article ";
Newpage. ListItem ["document date"] = DateTime. Now;
Newpage. Update ();
Newpage. CheckIn ("CheckIn"); // check in
SPFile pageFile = newpage. ListItem. File;
PageFile. Publish ("published by Code ");
}
Catch (Exception ex)
{
LogError (ex. Message); // Method for logging, which is omitted here
}
Finally
{
Web. Dispose ();
Site. Dispose ();
}

Our news has been published successfully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.