string linkUrl = "http://myServer:1001/sites/mySite/Documents";
string documentToLink = "http://myServer:1001/sites/mySite/Documents/myDoc.doc";
string linkName = "nome del link";
SPSite site = new SPSite(linkUrl);
SPWeb web = site.OpenWeb();
SPContentType ct = web.ContentTypes["Link to a Document"];
SPFolder myFolder = web.GetFolder(linkUrl);
SPFileCollection myCollection = myFolder.Files;
string linkToDoc = myFolder.Url + "/" + linkName + ".aspx";
string fileText = ""|%@ Assembly Name='{0}' %>\r\n |%@ Register TagPrefix='SharePoint' Namespace='Microsoft.SharePoint.WebControls' Assembly='Microsoft.SharePoint' %>\r\n |%@ Import Namespace='System.IO' %>\r\n |%@ Import Namespace='Microsoft.SharePoint' %>\r\n |%@ Import Namespace='Microsoft.SharePoint.Utilities' %>\r\n |%@ Import Namespace='Microsoft.SharePoint.WebControls' %>\r\n |html>\r\n |Head> |META Name='progid' Content='SharePoint.Link'>\r\n |body>\r\n |form id='Form1' runat='server'>\r\n |SharePoint:UrlRedirector id='Redirector1' runat='server' />\r\n |/form>\r\n |/body>\r\n |/html>";
StringBuilder sBuilder = new StringBuilder(fileText.Length + 400);
sBuilder.AppendFormat(fileText, typeof(SPDocumentLibrary).Assembly.FullName);
SPFile newFile = collection1.Add(linkToDoc, new UTF8Encoding().GetBytes(sBuilder.ToString()), false);
SPListItem newItem = newFile.Item;
newItem["ContentType"] = ct.Name;
newItem["URL"] = documentToLink + ", ";
newItem.UpdateOverwriteVersion();
if (newFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
{
newFile.CheckIn("");
}
|