本文整理汇总了C#中SPFolder.RequireNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# SPFolder.RequireNotNull方法的具体用法?C# SPFolder.RequireNotNull怎么用?C# SPFolder.RequireNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPFolder
的用法示例。
在下文中一共展示了SPFolder.RequireNotNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDocumentLink
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;
}