Links feature in SPFile

This MS internal document can serve as a good overview of the SPFile link management feature (credit also goes to Google search): SPFile link (pdf)

I tested SPFile.BackwardLinks and ForwardLinks properties. It seems that the BackwardLinks will list correct values immediately but ForwardLinks doesn’t do that until the file is checked in. For example, in CSDG 1234.ppt I create a link to 1.txt. Before checkin, 1.txt has CSDG 1234.ppt in BackwardLinks but CSDG 1234.ppt doesn’t have 1.txt in ForwardLinks, until I check in CSDG 1234.ppt. That’s interesting… But I guess it doesn’t really matter in our case.

I didn’t find a complete list of ‘parsed document types’ mentioned in above pdf file. So far, Word, Powerpoint and HTM files are working.

Things worth noting:

  • File is updated immediately after calling ReplaceLink – no need to call Update().
  • For HTM file, ForwardLinks include all kinds of resources linked in the main HTM file: htm, image, js, xml etc. It does NOT combine duplicated links.
  • If SPLink.IsBroken is false, it does NOT mean that the link is valid. For a external link (such as http://google.com), this property is always false. You have to also check IsInternal to detect an internal broken link. That means you know for sure it’s a broken link when (IsInternal==true && IsBroken==true). ServerRelativeUrl can not be used to determine that. In one particular case, there is link pointing to ../../../../../a/foler/strucutre/not/exist/afile.doc, the IsBroken property is false. The IsInternal value is false also, and ServerRealtiveUrl is ../../../../../a/foler/strucutre/not/exist/afile.doc.
Advertisements
This entry was posted in Document library. Bookmark the permalink.

2 Responses to Links feature in SPFile

  1. kunz says:

    Thank you! i’ve been looking for long time now to figure out how to access related resources via API. Now i use the SPFile.BackwardLinks Collection. Thanks good for the pdf u link to 😉 The stsadm command generates an xml that lists all related resources of a file (like site manager of the crm does).

  2. It seems that they do not support Excel files. I tried the property over the xls files (v.2003) and it does not captures any links. It would be very useful to support Excel files as well. Now we are in the conditions to parse the file using Excel readers :(.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s