本文整理汇总了C#中Web.GetListByTitle方法的典型用法代码示例。如果您正苦于以下问题:C# Web.GetListByTitle方法的具体用法?C# Web.GetListByTitle怎么用?C# Web.GetListByTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.GetListByTitle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetList
internal List GetList(Web web)
{
List list = null;
if (List != null)
{
list = List;
}
else if (Id != Guid.Empty)
{
list = web.Lists.GetById(Id);
}
else if (!string.IsNullOrEmpty(Title))
{
list = web.GetListByTitle(Title);
if (list == null)
{
list = web.GetListByUrl(Title);
}
}
if (list != null)
{
web.Context.Load(list, l => l.Id, l => l.BaseTemplate, l => l.OnQuickLaunch, l => l.DefaultViewUrl, l => l.Title, l => l.Hidden, l => l.ContentTypesEnabled, l => l.RootFolder.ServerRelativeUrl);
web.Context.ExecuteQueryRetry();
}
return list;
}
示例2: CreateSharePointRepositoryList
public static List CreateSharePointRepositoryList(Web web, string title, string description, string url)
{
List _requestList = web.GetListByTitle(title);
if(_requestList == null) //List Doesnt Existing
{
var _listCreation = new ListCreationInformation()
{
Title = title,
TemplateType = (int)ListTemplateType.GenericList,
Description = description,
Url = url
};
_requestList = web.Lists.Add(_listCreation);
web.Context.Load(_requestList);
web.Context.ExecuteQuery();
}
var _fields = CreateListFields(web);
var _contentID = CreateContentType(web, SiteRequestList.CONTENTTYPE_NAME,
SiteRequestList.CONTENTTYPE_DESCRIPTION,
SiteRequestList.DEFAULT_CTYPE_GROUP,
SiteRequestList.CONTENTTYPE_ID);
//add fields to CT
BindFieldsToContentType(web, SiteRequestList.CONTENTTYPE_ID, _fields);
AddContentTypeToList(web, SiteRequestList.CONTENTTYPE_ID, SiteRequestList.TITLE, _fields);
return _requestList;
}
示例3: AddContentTypeToList
private void AddContentTypeToList(Web web, string contentTypeId, string listName, IEnumerable<Field> fields) {
Debug.WriteLine("CType: {0}, List: {1}", contentTypeId, listName);
var list = web.GetListByTitle(listName);
if (!list.ContentTypeExistsById(contentTypeId))
web.AddContentTypeToListById(listName, contentTypeId);
list.ContentTypesEnabled = true;
list.Update();
list.RefreshLoad();
var contentType = web.ContentTypes.GetById(contentTypeId);
var defaultView = list.DefaultView;
web.Context.Load(contentType);
web.Context.Load(defaultView);
web.Context.Load(defaultView.ViewFields);
web.Context.ExecuteQuery();
foreach (var field in fields) {
// add the fields to the default view
if (field.FieldTypeKind != FieldType.Note &&
!defaultView.ViewFields.Contains(field.InternalName)) {
defaultView.ViewFields.Add(field.InternalName);
Debug.WriteLine(" added to default view");
}
defaultView.Update();
}
web.Context.ExecuteQuery();
// Item content type
DeleteContentTypeFromList(web, list, "Item");
}
示例4: CreateList
protected string CreateList(Web web, string listName, string listDescription, string listUrl) {
try {
var testList = web.GetListByTitle(listName);
if (testList != null)
// leave if the list is valid
return testList.Id.ToString();
}
catch { }
ListCreationInformation creationInfo = new ListCreationInformation();
creationInfo.Title = listName;
creationInfo.Description = listDescription;
creationInfo.Url = listUrl;
creationInfo.TemplateType = (int)ListTemplateType.GenericList;
List list = web.Lists.Add(creationInfo);
web.Context.Load(list);
web.Context.ExecuteQuery();
return list.Id.ToString();
}
示例5: UploadAssets
private static void UploadAssets(ClientContext ctx, Web web, bool rethrow = false)
{
Console.WriteLine("Begin file upload...");
try
{
// Get the path to the file which we are about to deploy
//string file = System.Web.Hosting.HostingEnvironment.MapPath(string.Format("~/{0}", "Content/MyPSC.png"));
Console.WriteLine("Environment web root path: {0}", Environment.GetEnvironmentVariable("WEBROOT_PATH"));
string file = Environment.GetEnvironmentVariable("WEBROOT_PATH") + "\\Content\\MyPSC.png";
Console.WriteLine("Attempting to upload file {0}...", file);
//Get site assets library
List assetLibrary = web.GetListByTitle("Site Assets");
ctx.Load(assetLibrary, a => a.RootFolder);
// Use CSOM to uplaod the file in
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(file);
newFile.Url = "MyPSC.png";
newFile.Overwrite = true;
Microsoft.SharePoint.Client.File uploadFile = assetLibrary.RootFolder.Files.Add(newFile);
ctx.Load(uploadFile);
ctx.ExecuteQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error uploading file: {0}" + ex.Message);
if (rethrow)
{
throw;
}
}
}
示例6: AddListViewWebPartToPage
private static void AddListViewWebPartToPage(ClientContext ctx, Web web, string listTitle, string pageName, int row, int col)
{
List list = web.GetListByTitle(listTitle);
ctx.Load(list, l => l.Id, l => l.Title);
ctx.ExecuteQueryRetry();
OfficeDevPnP.Core.Entities.WebPartEntity wp = new OfficeDevPnP.Core.Entities.WebPartEntity
{
WebPartIndex = 2,
WebPartTitle = list.Title,
WebPartZone = "Left", //Not sure if we need this
WebPartXml = String.Format(ListViewWebPartXml, list.Id, list.Title)
};
web.AddWebPartToWikiPage("SitePages", wp, pageName, row, col, true);
}
示例7: AddListToQuickLaunch
private static void AddListToQuickLaunch(ClientContext ctx, Web web, string listTitle, string parentNodeTitle = "")
{
if (web.ListExists(listTitle))
{
List list = web.GetListByTitle(listTitle);
ctx.Load(list, s => s.DefaultViewUrl, s => s.Title);
ctx.ExecuteQuery();
web.AddNavigationNode(listTitle, new Uri(list.DefaultViewUrl, UriKind.Relative), parentNodeTitle, OfficeDevPnP.Core.Enums.NavigationType.QuickLaunch);
}
}
示例8: GetList
private List GetList(Web web)
{
var listUrlProperty = GetProperty("ListUrl");
if (!string.IsNullOrEmpty(listUrlProperty?.Value))
{
return web.GetListByUrl(listUrlProperty.Value);
}
var listIdProperty = GetProperty("ListId");
Guid listId;
if (TryParseGuidProperty(listIdProperty, out listId))
{
return web.Lists.GetById(listId);
}
var listNameProperty = GetProperty("ListName");
if (TryParseGuidProperty(listNameProperty, out listId))
{
return web.Lists.GetById(listId);
}
var listDisplayName = GetProperty("ListDisplayName");
if (!string.IsNullOrEmpty(listDisplayName?.Value))
{
return web.GetListByTitle(listDisplayName.Value);
}
return null;
}