简体   繁体   中英

SPListItem Properties returning wrong URL for Sharepoint Blog Posts and Announcements

I am writing an application that integrates select Sharepoint list items into an Activity Stream. I'm using Sharepoint 2010 and the new Event Receiver solution in Visual Studio.

The problem is that I want to be able to link back to the original items in my client's Sharepoint site, and the URLs that I get for Blog Post and Announcement list items using the SPListItem.Url property don't work.

For example, if my Blog Post is ListItemID #12, the Url that I get from SPListItem.Url is something like:

*Lists/Posts/12_000*

when what I need to actually navigate to the item is:

Lists/Posts/Post.aspx?ID=12

I can, of course, build the URLs myself by taking the List Url and adding '/Post.aspx.ID=' + the ItemID, but in the event a client has modified the out-of-the-box Blog Template and renamed the Post.aspx page the link would fail. Is there a property I'm not aware of that calls the Urls I need?

The same issue applies to Announcements, where getting the Url has become even more complicated in Sharepoint 2010 since they now seem to open in a javascript pop-up.

I had the same issue and I have resolved it by using

listItem.ParentList.DefaultDisplayFormUrl + ?ID=listItem.ID 

to get the post url. Seems to resolved it back to Lists/Post/Post.aspx?ID=xxx .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM