public SPFile AddDocumentLink(SPWeb web, SPFolder targetFolder, string documentPath, string documentName, string documentUrl) { web.RequireNotNull("web"); targetFolder.RequireNotNull("targetFolder"); documentPath.RequireNotNullOrEmpty("documentPath"); documentName.RequireNotNullOrEmpty("documentName"); documentUrl.RequireNotNullOrEmpty("documentUrl"); IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); IContentTypeOperations contentTypeOps = serviceLocator.GetInstance<IContentTypeOperations>(); string contentTypeName = "Link to a Document"; var contentType = web.AvailableContentTypes[contentTypeName]; SPDocumentLibrary DocLibrary = targetFolder.DocumentLibrary; if (null != DocLibrary) { bool LinkToDocumentApplied = false; foreach (SPContentType cType in DocLibrary.ContentTypes) { if (cType.Name == contentTypeName) { LinkToDocumentApplied = true; break; } } if (!LinkToDocumentApplied) { contentTypeOps.AddContentTypeToList(contentType, DocLibrary); } } var filePath = targetFolder.ServerRelativeUrl; if (!string.IsNullOrEmpty(documentPath)) { filePath += "/" + documentPath; } var currentFolder = web.GetFolder(filePath); var files = currentFolder.Files; var urlOfFile = currentFolder.Url + "/" + documentName + ".aspx"; var builder = new StringBuilder(aspxPageFormat.Length + 400); builder.AppendFormat(aspxPageFormat, typeof(SPDocumentLibrary).Assembly.FullName); var properties = new Hashtable(); properties["ContentTypeId"] = contentType.Id.ToString(); var file = files.Add(urlOfFile, new MemoryStream(new UTF8Encoding().GetBytes(builder.ToString())), properties, false, false); var item = file.Item; item["URL"] = documentUrl + ", "; item.UpdateOverwriteVersion(); return file; }