本文整理汇总了C#中Web.EnsureFolderPath方法的典型用法代码示例。如果您正苦于以下问题:C# Web.EnsureFolderPath方法的具体用法?C# Web.EnsureFolderPath怎么用?C# Web.EnsureFolderPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.EnsureFolderPath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
TokenParser parser = new TokenParser(web);
var context = web.Context as ClientContext;
if (!web.IsPropertyAvailable("ServerRelativeUrl"))
{
context.Load(web, w => w.ServerRelativeUrl);
context.ExecuteQuery();
}
foreach (var file in template.Files)
{
var folderName = parser.Parse(file.Folder);
if (folderName.ToLower().StartsWith((web.ServerRelativeUrl.ToLower())))
{
folderName = folderName.Substring(web.ServerRelativeUrl.Length);
}
var folder = web.EnsureFolderPath(folderName);
using (var stream = template.Connector.GetFileStream(file.Src))
{
folder.UploadFile(file.Src, stream, true);
}
}
}
示例2: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_Files);
var context = web.Context as ClientContext;
if (!web.IsPropertyAvailable("ServerRelativeUrl"))
{
context.Load(web, w => w.ServerRelativeUrl);
context.ExecuteQueryRetry();
}
foreach (var file in template.Files)
{
var folderName = file.Folder.ToParsedString();
if (folderName.ToLower().StartsWith((web.ServerRelativeUrl.ToLower())))
{
folderName = folderName.Substring(web.ServerRelativeUrl.Length);
}
var folder = web.EnsureFolderPath(folderName);
Microsoft.SharePoint.Client.File targetFile = null;
var checkedOut = false;
targetFile = folder.GetFile(file.Src);
if (targetFile != null)
{
if (file.Overwrite)
{
checkedOut = CheckOutIfNeeded(web, targetFile);
using (var stream = template.Connector.GetFileStream(file.Src))
{
targetFile = folder.UploadFile(file.Src, stream, file.Overwrite);
}
}
else
{
checkedOut = CheckOutIfNeeded(web, targetFile);
}
}
else
{
using (var stream = template.Connector.GetFileStream(file.Src))
{
targetFile = folder.UploadFile(file.Src, stream, file.Overwrite);
}
checkedOut = CheckOutIfNeeded(web, targetFile);
}
if (targetFile != null)
{
if (file.Properties != null && file.Properties.Any())
{
Dictionary<string, string> transformedProperties = file.Properties.ToDictionary(property => property.Key, property => property.Value.ToParsedString());
targetFile.SetFileProperties(transformedProperties, false); // if needed, the file is already checked out
}
if (file.WebParts != null && file.WebParts.Any())
{
if (!targetFile.IsPropertyAvailable("ServerRelativeUrl"))
{
web.Context.Load(targetFile, f => f.ServerRelativeUrl);
web.Context.ExecuteQuery();
}
var existingWebParts = web.GetWebParts(targetFile.ServerRelativeUrl);
foreach (var webpart in file.WebParts)
{
// check if the webpart is already set on the page
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
{
var wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = webpart.Title;
wpEntity.WebPartXml = webpart.Contents.ToParsedString().Trim(new[] { '\n', ' ' });
wpEntity.WebPartZone = webpart.Zone;
wpEntity.WebPartIndex = (int) webpart.Order;
web.AddWebPartToWebPartPage(targetFile.ServerRelativeUrl, wpEntity);
}
}
}
if (checkedOut)
{
targetFile.CheckIn("", CheckinType.MajorCheckIn);
web.Context.ExecuteQueryRetry();
}
}
}
}
示例3: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
web.EnsureProperties(w => w.ServerRelativeUrl, w => w.Url);
foreach (var file in template.Files)
{
var folderName = parser.ParseString(file.Folder);
if (folderName.ToLower().StartsWith((web.ServerRelativeUrl.ToLower())))
{
folderName = folderName.Substring(web.ServerRelativeUrl.Length);
}
var folder = web.EnsureFolderPath(folderName);
File targetFile = null;
var checkedOut = false;
targetFile = folder.GetFile(template.Connector.GetFilenamePart(file.Src));
if (targetFile != null)
{
if (file.Overwrite)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_and_overwriting_existing_file__0_, file.Src);
checkedOut = CheckOutIfNeeded(web, targetFile);
using (var stream = GetFileStream(template, file))
{
targetFile = UploadFile(template, file, folder, stream);
}
}
else
{
checkedOut = CheckOutIfNeeded(web, targetFile);
}
}
else
{
using (var stream = GetFileStream(template, file))
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_file__0_, file.Src);
targetFile = UploadFile(template, file, folder, stream);
}
checkedOut = CheckOutIfNeeded(web, targetFile);
}
if (targetFile != null)
{
if (file.Properties != null && file.Properties.Any())
{
Dictionary<string, string> transformedProperties = file.Properties.ToDictionary(property => property.Key, property => parser.ParseString(property.Value));
SetFileProperties(targetFile, transformedProperties, false);
}
if (file.WebParts != null && file.WebParts.Any())
{
targetFile.EnsureProperties(f => f.ServerRelativeUrl);
var existingWebParts = web.GetWebParts(targetFile.ServerRelativeUrl);
foreach (var webpart in file.WebParts)
{
// check if the webpart is already set on the page
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Adding_webpart___0___to_page, webpart.Title);
var wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = webpart.Title;
wpEntity.WebPartXml = parser.ParseString(webpart.Contents).Trim(new[] { '\n', ' ' });
wpEntity.WebPartZone = webpart.Zone;
wpEntity.WebPartIndex = (int)webpart.Order;
web.AddWebPartToWebPartPage(targetFile.ServerRelativeUrl, wpEntity);
}
}
}
if (checkedOut)
{
targetFile.CheckIn("", CheckinType.MajorCheckIn);
web.Context.ExecuteQueryRetry();
}
// Don't set security when nothing is defined. This otherwise breaks on files set outside of a list
if (file.Security != null &&
(file.Security.ClearSubscopes == true || file.Security.CopyRoleAssignments == true || file.Security.RoleAssignments.Count > 0))
{
targetFile.ListItemAllFields.SetSecurity(parser, file.Security);
}
}
}
}
return parser;
}
示例4: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// Check if this is not a noscript site as we're not allowed to write to the web property bag is that one
bool isNoScriptSite = web.IsNoScriptSite();
var context = web.Context as ClientContext;
web.EnsureProperties(w => w.ServerRelativeUrl, w => w.Url);
// Build on the fly the list of additional files coming from the Directories
var directoryFiles = new List<Model.File>();
foreach (var directory in template.Directories)
{
var metadataProperties = directory.GetMetadataProperties();
directoryFiles.AddRange(directory.GetDirectoryFiles(metadataProperties));
}
foreach (var file in template.Files.Union(directoryFiles))
{
var folderName = parser.ParseString(file.Folder);
if (folderName.ToLower().StartsWith((web.ServerRelativeUrl.ToLower())))
{
folderName = folderName.Substring(web.ServerRelativeUrl.Length);
}
if (SkipFile(isNoScriptSite, file.Src, folderName))
{
// add log message
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Files_SkipFileUpload, file.Src, folderName);
continue;
}
var folder = web.EnsureFolderPath(folderName);
var checkedOut = false;
var targetFile = folder.GetFile(template.Connector.GetFilenamePart(file.Src));
if (targetFile != null)
{
if (file.Overwrite)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_and_overwriting_existing_file__0_, file.Src);
checkedOut = CheckOutIfNeeded(web, targetFile);
using (var stream = GetFileStream(template, file))
{
targetFile = UploadFile(template, file, folder, stream);
}
}
else
{
checkedOut = CheckOutIfNeeded(web, targetFile);
}
}
else
{
using (var stream = GetFileStream(template, file))
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_file__0_, file.Src);
targetFile = UploadFile(template, file, folder, stream);
}
checkedOut = CheckOutIfNeeded(web, targetFile);
}
if (targetFile != null)
{
if (file.Properties != null && file.Properties.Any())
{
Dictionary<string, string> transformedProperties = file.Properties.ToDictionary(property => property.Key, property => parser.ParseString(property.Value));
SetFileProperties(targetFile, transformedProperties, false);
}
#if !SP2013
bool webPartsNeedLocalization = false;
#endif
if (file.WebParts != null && file.WebParts.Any())
{
targetFile.EnsureProperties(f => f.ServerRelativeUrl);
var existingWebParts = web.GetWebParts(targetFile.ServerRelativeUrl).ToList();
foreach (var webPart in file.WebParts)
{
// check if the webpart is already set on the page
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == parser.ParseString(webPart.Title)) == null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Adding_webpart___0___to_page, webPart.Title);
var wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = parser.ParseString(webPart.Title);
wpEntity.WebPartXml = parser.ParseString(webPart.Contents).Trim(new[] { '\n', ' ' });
wpEntity.WebPartZone = webPart.Zone;
wpEntity.WebPartIndex = (int)webPart.Order;
var wpd = web.AddWebPartToWebPartPage(targetFile.ServerRelativeUrl, wpEntity);
#if !SP2013
if (webPart.Title.ContainsResourceToken())
{
//.........这里部分代码省略.........
示例5: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(CoreResources.Provisioning_ObjectHandlers_Files))
{
var context = web.Context as ClientContext;
if (!web.IsPropertyAvailable("ServerRelativeUrl"))
{
context.Load(web, w => w.ServerRelativeUrl);
context.ExecuteQueryRetry();
}
foreach (var file in template.Files)
{
var folderName = parser.ParseString(file.Folder);
if (folderName.ToLower().StartsWith((web.ServerRelativeUrl.ToLower())))
{
folderName = folderName.Substring(web.ServerRelativeUrl.Length);
}
var folder = web.EnsureFolderPath(folderName);
File targetFile = null;
var checkedOut = false;
targetFile = folder.GetFile(template.Connector.GetFilenamePart(file.Src));
if (targetFile != null)
{
if (file.Overwrite)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_and_overwriting_existing_file__0_,file.Src);
checkedOut = CheckOutIfNeeded(web, targetFile);
using (var stream = template.Connector.GetFileStream(file.Src))
{
targetFile = folder.UploadFile(template.Connector.GetFilenamePart(file.Src), stream, file.Overwrite);
}
}
else
{
checkedOut = CheckOutIfNeeded(web, targetFile);
}
}
else
{
using (var stream = template.Connector.GetFileStream(file.Src))
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_file__0_, file.Src);
targetFile = folder.UploadFile(template.Connector.GetFilenamePart(file.Src), stream, file.Overwrite);
}
checkedOut = CheckOutIfNeeded(web, targetFile);
}
if (targetFile != null)
{
if (file.Properties != null && file.Properties.Any())
{
Dictionary<string, string> transformedProperties = file.Properties.ToDictionary(property => property.Key, property => parser.ParseString(property.Value));
targetFile.SetFileProperties(transformedProperties, false); // if needed, the file is already checked out
}
if (file.WebParts != null && file.WebParts.Any())
{
if (!targetFile.IsPropertyAvailable("ServerRelativeUrl"))
{
web.Context.Load(targetFile, f => f.ServerRelativeUrl);
web.Context.ExecuteQuery();
}
var existingWebParts = web.GetWebParts(targetFile.ServerRelativeUrl);
foreach (var webpart in file.WebParts)
{
// check if the webpart is already set on the page
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Adding_webpart___0___to_page,webpart.Title);
var wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = webpart.Title;
wpEntity.WebPartXml = parser.ParseString(webpart.Contents).Trim(new[] { '\n', ' ' });
wpEntity.WebPartZone = webpart.Zone;
wpEntity.WebPartIndex = (int)webpart.Order;
web.AddWebPartToWebPartPage(targetFile.ServerRelativeUrl, wpEntity);
}
}
}
if (checkedOut)
{
targetFile.CheckIn("", CheckinType.MajorCheckIn);
web.Context.ExecuteQueryRetry();
}
}
}
}
//.........这里部分代码省略.........