Um in einer Dokumentenbibliothek ein Item vom Typ “Verknüpfung zu einem Dokument” zu erstellen bindet man den entsprechenden Inhaltstyp ein und wählt diesen dann als Typ für das neue Dokument aus:
danach wird eine aspx-Seite generiert:
Die generierte aspx-Seite schaut bis auf die Weiterleitung immer gleich aus:
<%@ Assembly Name=’Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ %> <%@ Register TagPrefix=’SharePoint’ Namespace=’Microsoft.SharePoint.WebControls’ Assembly=’Microsoft.SharePoint’ %> <%@ Import Namespace=’System.IO’ %> <%@ Import Namespace=’Microsoft.SharePoint’ %> <%@ Import Namespace=’Microsoft.SharePoint.Utilities’ %> <%@ Import Namespace=’Microsoft.SharePoint.WebControls’ %> <html xmlns:mso=”urn:schemas-microsoft-com:office:office” xmlns:msdt=”uuid:C2F41010-65B3-11d1-A29F-00AA00C14882″> <head> <meta name=’progid’ content=’SharePoint.Link’ /> <!–[if gte mso 9]><SharePoint:CTFieldRefs runat=server Prefix=”mso:” FieldList=”FileLeafRef,URL”><xml> <mso:CustomDocumentProperties> <mso:ContentTypeId msdt:dt=”string”>0x01010A00D042FE898DD0E44AA4B47EA393D7711E</mso:ContentTypeId> <mso:IconOverlay msdt:dt=”string”>|de|linkoverlay.gif</mso:IconOverlay> <mso:URL msdt:dt=”string”>http://gruber-t.de, http://gruber-t.de</mso:URL> </mso:CustomDocumentProperties> </xml></SharePoint:CTFieldRefs><![endif]–> </head> <body> <form id=’Form1′ runat=’server’> <SharePoint:UrlRedirector id=’Redirector1′ runat=’server’ /> </form> </body> </html>
Dieses Verhalten sollte man auch im Hinterkopf behalten, will man das ganze programmatisch erstellen, hier wie es prinzipiell aussehen könnte:
…
SPContentType CT = list.ContentTypes["Verknüpfung zu einem Dokument"];
string aspxSeite = … //hier muss die oben genannte aspx-Seite zusammengebaut werden
SPFile file = list.rootFolder.Files.Add(“LinkZumDokument” + “.aspx”, UTF8Encoding.UTF8.GetBytes(aspxSeite));
SPListItem item = file.Item;
item["ContentTypeId"] = CT.Id;
item.Update();
SPFieldUrlValue fieldUrl = new SPFieldUrlValue() { Description = documentName, Url = documentUrl };
item["URL"] = fieldUrl;
item.Update();


