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.