本文整理汇总了C#中Folder.IsPropertyAvailable方法的典型用法代码示例。如果您正苦于以下问题:C# Folder.IsPropertyAvailable方法的具体用法?C# Folder.IsPropertyAvailable怎么用?C# Folder.IsPropertyAvailable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder.IsPropertyAvailable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchItemByName
protected ListItem SearchItemByName(List list, Folder folder, string pageName)
{
var context = list.Context;
if (folder != null)
{
if (!folder.IsPropertyAvailable("ServerRelativeUrl"))
{
folder.Context.Load(folder, f => f.ServerRelativeUrl);
folder.Context.ExecuteQueryWithTrace();
}
}
var dQuery = new CamlQuery();
string QueryString = "<View><Query><Where>" +
"<Eq>" +
"<FieldRef Name=\"FileLeafRef\"/>" +
"<Value Type=\"Text\">" + pageName + "</Value>" +
"</Eq>" +
"</Where></Query></View>";
dQuery.ViewXml = QueryString;
if (folder != null)
dQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;
var collListItems = list.GetItems(dQuery);
context.Load(collListItems);
context.ExecuteQueryWithTrace();
return collListItems.FirstOrDefault();
}
示例2: EnsureFolder
/// <summary>
/// Ensure that the folder structure is created. This also ensures hierarchy of folders.
/// </summary>
/// <param name="web">Web to be processed - can be root web or sub site</param>
/// <param name="parentFolder">Parent folder</param>
/// <param name="folderPath">Folder path</param>
/// <returns>The folder structure</returns>
public static Folder EnsureFolder(this Web web, Folder parentFolder, string folderPath)
{
if (!web.IsPropertyAvailable("ServerRelativeUrl") || !parentFolder.IsPropertyAvailable("ServerRelativeUrl"))
{
web.Context.Load(web, w => w.ServerRelativeUrl);
web.Context.Load(parentFolder, f => f.ServerRelativeUrl);
web.Context.ExecuteQueryRetry();
}
var parentWebRelativeUrl = parentFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length);
var webRelativeUrl = parentWebRelativeUrl + (parentWebRelativeUrl.EndsWith("/") ? "" : "/") + folderPath;
return web.EnsureFolderPath(webRelativeUrl);
}
示例3: EnsureFolder
/// <summary>
/// Ensure that the folder structure is created. This also ensures hierarchy of folders.
/// </summary>
/// <param name="web">Web to be processed - can be root web or sub site</param>
/// <param name="parentFolder">Parent folder</param>
/// <param name="folderPath">Folder path</param>
/// <returns>The folder structure</returns>
public static Folder EnsureFolder(this Web web, Folder parentFolder, string folderPath)
{
if (!web.IsPropertyAvailable("ServerRelativeUrl") || !parentFolder.IsPropertyAvailable("ServerRelativeUrl"))
{
web.Context.Load(web, w => w.ServerRelativeUrl);
web.Context.Load(parentFolder, f => f.ServerRelativeUrl);
web.Context.ExecuteQuery();
}
var parentWebRelativeUrl = parentFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length);
var webRelativeUrl = parentWebRelativeUrl + (parentWebRelativeUrl.EndsWith("/") ? "" : "/") + folderPath;
return web.EnsureFolderPath(webRelativeUrl);
//// Split up the incoming path so we have the first element as the a new sub-folder name
//// and add it to ParentFolder folders collection
//string[] pathElements = folderPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
//string head = pathElements[0];
//Folder newFolder = parentFolder.Folders.Add(head);
//web.Context.Load(newFolder);
//web.Context.ExecuteQuery();
//// If we have subfolders to create then the length of PathElements will be greater than 1
//if (pathElements.Length > 1)
//{
// // If we have more nested folders to create then reassemble the folder path using what we have left i.e. the tail
// string Tail = string.Empty;
// for (int i = 1; i < pathElements.Length; i++)
// {
// Tail = Tail + "/" + pathElements[i];
// }
// // Then make a recursive call to create the next subfolder
// return web.EnsureFolder(newFolder, Tail);
//}
//else
//{
// // This ensures that the folder at the end of the chain gets returned
// return newFolder;
//}
}
示例4: SearchFileByName
protected File SearchFileByName(List list, Folder folder, string pageName)
{
var context = list.Context;
if (folder != null)
{
if (!folder.IsPropertyAvailable("ServerRelativeUrl")
// || !folder.IsPropertyAvailable("Properties"))
)
{
folder.Context.Load(folder, f => f.ServerRelativeUrl);
//folder.Context.Load(folder, f => f.Properties);
folder.Context.ExecuteQueryWithTrace();
}
}
// one more time..
var dQuery = new CamlQuery();
string QueryString = "<View><Query><Where>" +
"<Eq>" +
"<FieldRef Name=\"FileLeafRef\"/>" +
"<Value Type=\"Text\">" + pageName + "</Value>" +
"</Eq>" +
"</Where></Query></View>";
dQuery.ViewXml = QueryString;
if (folder != null)
dQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;
var collListItems = list.GetItems(dQuery);
context.Load(collListItems);
context.ExecuteQueryWithTrace();
var item = collListItems.FirstOrDefault();
if (item != null)
return item.File;
//one more time
// by full path
var fileServerRelativePath = UrlUtility.CombineUrl(folder.ServerRelativeUrl, pageName);
File file = null;
var scope = new ExceptionHandlingScope(context);
using (scope.StartScope())
{
using (scope.StartTry())
{
file = list.ParentWeb.GetFileByServerRelativeUrl(fileServerRelativePath);
context.Load(file);
}
using (scope.StartCatch())
{
}
}
context.ExecuteQueryWithTrace();
// Forms folder im the libraries
// otherwise pure list items search
if (!scope.HasException && file != null && file.ServerObjectIsNull != null)
{
context.Load(file);
context.Load(file, f => f.Exists);
context.ExecuteQueryWithTrace();
if (file.Exists)
return file;
}
return null;
}