本文整理汇总了C#中Web.GetCatalog方法的典型用法代码示例。如果您正苦于以下问题:C# Web.GetCatalog方法的具体用法?C# Web.GetCatalog怎么用?C# Web.GetCatalog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.GetCatalog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeployFileToThemeFolderSite
private void DeployFileToThemeFolderSite(ClientContext clientContext, Web web, string sourceAddress)
{
// Get the path to the file which we are about to deploy
string file = sourceAddress;
List themesList = web.GetCatalog(123);
// get the theme list
clientContext.Load(themesList);
clientContext.ExecuteQuery();
Folder rootfolder = themesList.RootFolder;
clientContext.Load(rootfolder);
clientContext.Load(rootfolder.Folders);
clientContext.ExecuteQuery();
Folder folder15 = rootfolder;
foreach (Folder folder in rootfolder.Folders)
{
if (folder.Name == "15")
{
folder15 = folder;
break;
}
}
// Use CSOM to uplaod the file in
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(file);
newFile.Url = folder15.ServerRelativeUrl + "/" + Path.GetFileName(sourceAddress);
newFile.Overwrite = true;
Microsoft.SharePoint.Client.File uploadFile = folder15.Files.Add(newFile);
clientContext.Load(uploadFile);
clientContext.ExecuteQuery();
}
示例2: SetThemeBasedOnName
public void SetThemeBasedOnName(ClientContext ctx, Web web, Web rootWeb, string themeName)
{
// Let's get instance to the composite look gallery
List themeList = rootWeb.GetCatalog(124);
ctx.Load(themeList);
ctx.ExecuteQuery();
CamlQuery query = new CamlQuery();
string camlString = @"
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Name' />
<Value Type='Text'>{0}</Value>
</Eq>
</Where>
</Query>
</View>";
// Let's update the theme name accordingly
camlString = string.Format(camlString, themeName);
query.ViewXml = camlString;
var found = themeList.GetItems(query);
ctx.Load(found);
ctx.ExecuteQuery();
if (found.Count > 0)
{
Microsoft.SharePoint.Client.ListItem themeEntry = found[0];
//Set the properties for applying custom theme which was jus uplaoded
string spColorURL = null;
if (themeEntry["ThemeUrl"] != null && themeEntry["ThemeUrl"].ToString().Length > 0)
{
spColorURL = MakeAsRelativeUrl((themeEntry["ThemeUrl"] as FieldUrlValue).Url);
}
string spFontURL = null;
if (themeEntry["FontSchemeUrl"] != null && themeEntry["FontSchemeUrl"].ToString().Length > 0)
{
spFontURL = MakeAsRelativeUrl((themeEntry["FontSchemeUrl"] as FieldUrlValue).Url);
}
string backGroundImage = null;
if (themeEntry["ImageUrl"] != null && themeEntry["ImageUrl"].ToString().Length > 0)
{
backGroundImage = MakeAsRelativeUrl((themeEntry["ImageUrl"] as FieldUrlValue).Url);
}
// Set theme for demonstration
web.ApplyTheme(spColorURL,
spFontURL,
backGroundImage,
false);
// Let's also update master page, if needed
if (themeEntry["MasterPageUrl"] != null && themeEntry["MasterPageUrl"].ToString().Length > 0)
{
web.MasterUrl = MakeAsRelativeUrl((themeEntry["MasterPageUrl"] as FieldUrlValue).Url); ;
}
ctx.ExecuteQuery();
}
}
示例3: SetMasterPageMetadata
private static void SetMasterPageMetadata(Web web, File uploadFile) {
var parentContentTypeId = "0x010105"; // Master Page
var gallery = web.GetCatalog(116);
web.Context.Load(gallery, g => g.ContentTypes);
web.Context.ExecuteQuery();
var contentTypeId = gallery.ContentTypes.FirstOrDefault(ct => ct.StringId.StartsWith(parentContentTypeId)).StringId;
var item = uploadFile.ListItemAllFields;
web.Context.Load(item);
item["ContentTypeId"] = contentTypeId;
item["UIVersion"] = Convert.ToString(15);
item["MasterPageDescription"] = "Violin master page";
item.Update();
web.Context.ExecuteQuery();
}
示例4: AddComposedLooks
private void AddComposedLooks(Microsoft.SharePoint.Client.ClientContext context, ShWeb configWeb, Web web, ShComposedLook composedLook)
{
if (composedLook != null)
{
Log.Debug("Setting Composed Look for web " + configWeb.Name);
var themeUrl = string.Empty;
var fontSchemeUrl = string.Empty;
List themeList = web.GetCatalog(124);
web.Context.Load(themeList);
web.Context.ExecuteQuery();
// We are assuming that the theme exists
CamlQuery query = new CamlQuery();
string camlString = @"
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Name' />
<Value Type='Text'>{0}</Value>
</Eq>
</Where>
</Query>
</View>";
camlString = string.Format(camlString, composedLook.Name);
query.ViewXml = camlString;
var found = themeList.GetItems(query);
web.Context.Load(found);
web.Context.ExecuteQuery();
if (found.Count == 0)
{
if (!web.IsObjectPropertyInstantiated("ServerRelativeUrl"))
{
context.Load(web);
context.ExecuteQuery();
}
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem item = themeList.AddItem(itemInfo);
item["Name"] = composedLook.Name;
item["Title"] = composedLook.Title;
if (!string.IsNullOrEmpty(composedLook.ThemeUrl))
{
themeUrl = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", System.IO.Path.GetFileName(composedLook.ThemeUrl)));
item["ThemeUrl"] = themeUrl;
}
if (!string.IsNullOrEmpty(composedLook.FontSchemeUrl))
{
fontSchemeUrl = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", System.IO.Path.GetFileName(composedLook.FontSchemeUrl)));
item["FontSchemeUrl"] = fontSchemeUrl;
}
if (string.IsNullOrEmpty(composedLook.MasterPageUrl))
{
item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, "/_catalogs/masterpage/seattle.master");
}
else
{
item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/masterpage/{0}", Path.GetFileName(composedLook.MasterPageUrl)));
}
item["DisplayOrder"] = 11;
item.Update();
context.ExecuteQuery();
}
else
{
Microsoft.SharePoint.Client.ListItem item = found[0];
themeUrl = MakeAsRelativeUrl((item["ThemeUrl"] as FieldUrlValue).Url);
fontSchemeUrl = MakeAsRelativeUrl((item["FontSchemeUrl"] as FieldUrlValue).Url);
}
web.ApplyTheme(themeUrl, fontSchemeUrl, null, false);
context.ExecuteQuery();
}
}
示例5: SetThemeToWebImplementation
private static void SetThemeToWebImplementation(this Web web, Web rootWeb, string themeName)
{
if (rootWeb == null)
throw new ArgumentNullException("rootWeb");
if (string.IsNullOrEmpty(themeName))
throw new ArgumentNullException("themeName");
LoggingUtility.Internal.TraceInformation((int)EventId.SetTheme, CoreResources.BrandingExtension_SetTheme, themeName, web.Context.Url);
// Let's get instance to the composite look gallery
List themeList = rootWeb.GetCatalog((int)ListTemplateType.DesignCatalog);
rootWeb.Context.Load(themeList);
LoggingUtility.Internal.TraceVerbose("Getting theme list (catalog 124)");
rootWeb.Context.ExecuteQuery();
// Double checking that theme exists
if (rootWeb.ThemeEntryExists(themeName, themeList))
{
// Let's update the theme name accordingly
CamlQuery query = new CamlQuery();
// Find the theme by themeName
string camlString = string.Format(CAML_QUERY_FIND_BY_FILENAME, themeName);
query.ViewXml = camlString;
var found = themeList.GetItems(query);
rootWeb.Context.Load(found);
LoggingUtility.Internal.TraceVerbose("Getting theme: {0}", themeName);
rootWeb.Context.ExecuteQuery();
if (found.Count > 0)
{
ListItem themeEntry = found[0];
//Set the properties for applying custom theme which was just uploaded
string spColorURL = null;
if (themeEntry["ThemeUrl"] != null && themeEntry["ThemeUrl"].ToString().Length > 0)
{
spColorURL = UrlUtility.MakeRelativeUrl((themeEntry["ThemeUrl"] as FieldUrlValue).Url);
}
string spFontURL = null;
if (themeEntry["FontSchemeUrl"] != null && themeEntry["FontSchemeUrl"].ToString().Length > 0)
{
spFontURL = UrlUtility.MakeRelativeUrl((themeEntry["FontSchemeUrl"] as FieldUrlValue).Url);
}
string backGroundImage = null;
if (themeEntry["ImageUrl"] != null && themeEntry["ImageUrl"].ToString().Length > 0)
{
backGroundImage = UrlUtility.MakeRelativeUrl((themeEntry["ImageUrl"] as FieldUrlValue).Url);
}
LoggingUtility.Internal.TraceVerbose("Apply theme '{0}', '{1}', '{2}'.", spColorURL, spFontURL, backGroundImage);
// Set theme for demonstration
// TODO: Why is shareGenerated false? If deploying to root an inheriting, then maybe use shareGenerated = true.
web.ApplyTheme(spColorURL,
spFontURL,
backGroundImage,
false);
web.Context.ExecuteQuery();
LoggingUtility.Internal.TraceVerbose("Theme applied");
// Let's also update master page, if needed
if (themeEntry["MasterPageUrl"] != null && themeEntry["MasterPageUrl"].ToString().Length > 0)
{
var masterUrl = UrlUtility.MakeRelativeUrl((themeEntry["MasterPageUrl"] as FieldUrlValue).Url);
web.SetMasterPageForSiteByUrl(masterUrl);
web.SetCustomMasterPageForSiteByUrl(masterUrl);
}
}
else
{
LoggingUtility.Internal.TraceError((int)EventId.ThemeMissing, CoreResources.BrandingExtension_ThemeMissing, themeName);
}
}
else
{
LoggingUtility.Internal.TraceError((int)EventId.ThemeMissing, CoreResources.BrandingExtension_ThemeMissing, themeName);
}
}
示例6: SetPageLayoutMetadata
private static void SetPageLayoutMetadata(Web web, File uploadFile, string title, string publishingAssociatedContentType) {
var parentContentTypeId = "0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE811"; //Page Layout
var gallery = web.GetCatalog(116);
web.Context.Load(gallery, g => g.ContentTypes);
web.Context.ExecuteQuery();
var contentTypeId = gallery.ContentTypes.FirstOrDefault(ct => ct.StringId.StartsWith(parentContentTypeId)).StringId;
var item = uploadFile.ListItemAllFields;
web.Context.Load(item);
item["ContentTypeId"] = contentTypeId;
item["Title"] = title;
item["PublishingAssociatedContentType"] = publishingAssociatedContentType;
item.Update();
web.Context.ExecuteQuery();
}
示例7: DeployFiles
/// <summary>
/// This function is responsible to upload theme files which are in App
/// to catalog list
/// </summary>
/// <param name="web"></param>
public void DeployFiles(Web web)
{
try
{
List themesCatalog = web.GetCatalog(123);
Folder rootFolder = themesCatalog.RootFolder;
web.Context.Load(rootFolder);
web.Context.Load(rootFolder.Folders);
web.Context.ExecuteQuery();
Folder folder15 = rootFolder.Folders.FirstOrDefault(f => f.Name == "15");
#region GetFiles
string path = HostingEnvironment.MapPath(string.Format("~/Resources"));
// Get Theme Directories from the app physical path on IIS
string[] themeDirectories = Directory.GetDirectories(path);
foreach (string themeDirUrl in themeDirectories)
{
//am considering theme directory name as the theme name
// so getting theme directory name
string themeFolderName = themeDirUrl.Remove(0, path.Length + 1);
string[] themeFiles = Directory.GetFiles(themeDirUrl);
uploadFile(web, themeFiles, folder15, themeFolderName);
}
#endregion
}
catch (Exception ex)
{
// implment loggin
}
}
示例8: PublishMasterPage
public static string PublishMasterPage(Web web, string mpFilePath, string title, string description)
{
try
{
Logger.LogInfoMessage(String.Format("Publishing Master Page File: {0} ...", mpFilePath), false);
List mpGallery = web.GetCatalog((int)ListTemplateType.MasterPageCatalog);
Folder mpGalleryRoot = mpGallery.RootFolder;
web.Context.Load(mpGallery);
web.Context.Load(mpGalleryRoot);
web.Context.ExecuteQuery();
File mpFile = GetFileFromWeb(web, mpFilePath);
if (mpFile == null)
{
Logger.LogErrorMessage(String.Format("UploadMasterPage() failed for {0}: Error=File Not Found", web.Url), false);
return String.Empty;
}
if (mpGallery.ForceCheckout || mpGallery.EnableVersioning)
{
if (mpFile.CheckOutType == CheckOutType.None)
{
mpFile.CheckOut();
}
}
ListItem fileListItem = mpFile.ListItemAllFields;
fileListItem["MasterPageDescription"] = description;
fileListItem["UIVersion"] = "15";
if (mpGallery.AllowContentTypes && mpGallery.ContentTypesEnabled)
{
fileListItem["Title"] = title;
fileListItem["ContentTypeId"] = Constants.MASTERPAGE_CONTENT_TYPE;
}
fileListItem.Update();
if (mpGallery.ForceCheckout || mpGallery.EnableVersioning)
{
mpFile.CheckIn(string.Empty, CheckinType.MajorCheckIn);
if (mpGallery.EnableModeration)
{
mpFile.Approve("");
}
}
web.Context.ExecuteQuery();
Logger.LogSuccessMessage(String.Format("Published Master Page File: {0}", mpFile.ServerRelativeUrl), false);
return mpFile.ServerRelativeUrl;
}
catch (Exception ex)
{
Logger.LogErrorMessage(String.Format("UploadMasterPage() failed for {0}: Error={1}", web.Url, ex.Message), false);
return String.Empty;
}
}
示例9: AddNewThemeOptionToSite
/// <summary>
/// Creates new options to the look and feel section
/// </summary>
/// <param name="clientContext"></param>
/// <param name="web"></param>
private void AddNewThemeOptionToSite(ClientContext clientContext, Web web)
{
// Let's get instance to the composite look gallery
List themesOverviewList = web.GetCatalog(124);
clientContext.Load(themesOverviewList);
clientContext.ExecuteQuery();
// Is the item already in the list?
if (!ContosoThemeEntryExists(clientContext, web, themesOverviewList))
{
// Let's create new theme entry. Notice that theme selection is not available from UI in personal sites, so this is just for consistency sake
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem item = themesOverviewList.AddItem(itemInfo);
item["Name"] = "Contoso";
item["Title"] = "Contoso";
item["ThemeUrl"] = URLCombine(web.ServerRelativeUrl, "/_catalogs/theme/15/contoso.spcolor"); ;
item["FontSchemeUrl"] = URLCombine(web.ServerRelativeUrl, "/_catalogs/theme/15/contoso.spfont"); ;
item["ImageUrl"] = URLCombine(web.ServerRelativeUrl, "/_catalogs/theme/15/contosobg.jpg");
// Notice that we use oob master, but just as well you vould upload and use custom one
item["MasterPageUrl"] = URLCombine(web.ServerRelativeUrl, "/_catalogs/masterpage/seattle.master");
item["DisplayOrder"] = 0;
item.Update();
clientContext.ExecuteQuery();
}
}
示例10: SetThemeToWebImplementation
private static void SetThemeToWebImplementation(this Web web, Web rootWeb, string themeName)
{
// Let's get instance to the composite look gallery
List themeList = rootWeb.GetCatalog(124);
rootWeb.Context.Load(themeList);
rootWeb.Context.ExecuteQuery();
// Double checking that theme exists
if (rootWeb.ThemeEntryExists(themeName, themeList))
{
CamlQuery query = new CamlQuery();
string camlString = @"
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Name' />
<Value Type='Text'>{0}</Value>
</Eq>
</Where>
</Query>
</View>";
// Let's update the theme name accordingly
camlString = string.Format(camlString, themeName);
query.ViewXml = camlString;
var found = themeList.GetItems(query);
rootWeb.Context.Load(found);
rootWeb.Context.ExecuteQuery();
if (found.Count > 0)
{
ListItem themeEntry = found[0];
//Set the properties for applying custom theme which was jus uplaoded
string spColorURL = null;
if (themeEntry["ThemeUrl"] != null && themeEntry["ThemeUrl"].ToString().Length > 0)
{
spColorURL = UrlUtility.MakeRelativeUrl((themeEntry["ThemeUrl"] as FieldUrlValue).Url);
}
string spFontURL = null;
if (themeEntry["FontSchemeUrl"] != null && themeEntry["FontSchemeUrl"].ToString().Length > 0)
{
spFontURL = UrlUtility.MakeRelativeUrl((themeEntry["FontSchemeUrl"] as FieldUrlValue).Url);
}
string backGroundImage = null;
if (themeEntry["ImageUrl"] != null && themeEntry["ImageUrl"].ToString().Length > 0)
{
backGroundImage = UrlUtility.MakeRelativeUrl((themeEntry["ImageUrl"] as FieldUrlValue).Url);
}
// Set theme for demonstration
web.ApplyTheme(spColorURL,
spFontURL,
backGroundImage,
false);
// Let's also update master page, if needed
if (themeEntry["MasterPageUrl"] != null && themeEntry["MasterPageUrl"].ToString().Length > 0)
{
web.MasterUrl = UrlUtility.MakeRelativeUrl((themeEntry["MasterPageUrl"] as FieldUrlValue).Url); ;
}
web.Context.ExecuteQuery();
}
}
}
示例11: UploadWebPartFile
public static void UploadWebPartFile(Web web, string wpFileName, string localFilePath, string title, string description)
{
try
{
Logger.LogInfoMessage(String.Format("Uploading Web Part File: {0} ...", wpFileName), false);
List wpGallery = web.GetCatalog((int)ListTemplateType.WebPartCatalog);
Folder wpGalleryRoot = wpGallery.RootFolder;
web.Context.Load(wpGallery);
web.Context.Load(wpGalleryRoot);
web.Context.ExecuteQuery();
string wpFilePath = wpGalleryRoot.ServerRelativeUrl + "/" + wpFileName;
File wpFile = GetFileFromWeb(web, wpFilePath);
if (wpFile == null)
{
// Get the file name from the provided path
Byte[] fileBytes = System.IO.File.ReadAllBytes(localFilePath);
// Use CSOM to upload the file in
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = fileBytes;
newFile.Overwrite = true;
newFile.Url = wpFileName;
File uploadFile = wpGalleryRoot.Files.Add(newFile);
web.Context.Load(uploadFile);
web.Context.ExecuteQuery();
}
// Grab the file we just uploaded so we can edit its properties
wpFile = GetFileFromWeb(web, wpFilePath);
if (wpGallery.ForceCheckout || wpGallery.EnableVersioning)
{
if (wpFile.CheckOutType == CheckOutType.None)
{
wpFile.CheckOut();
}
}
ListItem fileListItem = wpFile.ListItemAllFields;
fileListItem["Title"] = title;
fileListItem["WebPartDescription"] = description;
fileListItem["Group"] = "Contoso Custom Web Parts";
fileListItem.Update();
if (wpGallery.ForceCheckout || wpGallery.EnableVersioning)
{
wpFile.CheckIn(string.Empty, CheckinType.MajorCheckIn);
if (wpGallery.EnableModeration)
{
wpFile.Approve("");
}
}
web.Context.ExecuteQuery();
Logger.LogSuccessMessage(String.Format("Uploaded Web Part File: {0}", wpFile.ServerRelativeUrl), false);
}
catch (Exception ex)
{
Logger.LogErrorMessage(String.Format("UploadWebPartFile() failed for {0}: Error={1}", web.Url, ex.Message), false);
}
}
示例12: UploadMasterPage
public static string UploadMasterPage(Web web, string mpFileName, string localFilePath, string title, string description)
{
try
{
Logger.LogInfoMessage(String.Format("Uploading Master Page File: {0} ...", mpFileName), false);
List mpGallery = web.GetCatalog((int)ListTemplateType.MasterPageCatalog);
Folder mpGalleryRoot = mpGallery.RootFolder;
web.Context.Load(mpGallery);
web.Context.Load(mpGalleryRoot);
web.Context.ExecuteQuery();
string mpFilePath = mpGalleryRoot.ServerRelativeUrl + "/" + mpFileName;
File mpFile = GetFileFromWeb(web, mpFilePath);
if (mpFile == null)
{
// Get the file name from the provided path
Byte[] fileBytes = System.IO.File.ReadAllBytes(localFilePath);
// Use CSOM to upload the file in
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = fileBytes;
newFile.Overwrite = true;
newFile.Url = mpFileName;
File uploadFile = mpGalleryRoot.Files.Add(newFile);
web.Context.Load(uploadFile);
web.Context.ExecuteQuery();
}
// Grab the file we just uploaded so we can edit its properties
mpFile = GetFileFromWeb(web, mpFilePath);
if (mpGallery.ForceCheckout || mpGallery.EnableVersioning)
{
if (mpFile.CheckOutType == CheckOutType.None)
{
mpFile.CheckOut();
}
}
ListItem fileListItem = mpFile.ListItemAllFields;
fileListItem["MasterPageDescription"] = description;
fileListItem["UIVersion"] = "15";
if (mpGallery.AllowContentTypes && mpGallery.ContentTypesEnabled)
{
fileListItem["Title"] = title;
fileListItem["ContentTypeId"] = Constants.MASTERPAGE_CONTENT_TYPE;
}
fileListItem.Update();
if (mpGallery.ForceCheckout || mpGallery.EnableVersioning)
{
mpFile.CheckIn(string.Empty, CheckinType.MajorCheckIn);
if (mpGallery.EnableModeration)
{
mpFile.Approve("");
}
}
web.Context.ExecuteQuery();
Logger.LogSuccessMessage(String.Format("Uploaded Master Page File: {0}", mpFile.ServerRelativeUrl), false);
return mpFile.ServerRelativeUrl;
}
catch (Exception ex)
{
Logger.LogErrorMessage(String.Format("UploadMasterPage() failed for {0}: Error={1}", web.Url, ex.Message), false);
return String.Empty;
}
}
示例13: UploadDisplayTemplateFileJS
public static void UploadDisplayTemplateFileJS(Web web, string dtFileName, string localFilePath, string displayTemplateFolderName, string title, string description)
{
try
{
Logger.LogInfoMessage(String.Format("Uploading Display Template JS File: {0} ...", dtFileName), false);
List mpGallery = web.GetCatalog((int)ListTemplateType.MasterPageCatalog);
Folder mpGalleryRoot = mpGallery.RootFolder;
web.Context.Load(mpGallery);
web.Context.Load(mpGalleryRoot);
web.Context.ExecuteQuery();
string serverRelativeFolderUrl = mpGalleryRoot.ServerRelativeUrl + "/Display Templates/" + displayTemplateFolderName;
Folder dtFolder = web.GetFolderByServerRelativeUrl(serverRelativeFolderUrl);
web.Context.Load(dtFolder);
web.Context.ExecuteQuery();
string dtFilePath = dtFolder.ServerRelativeUrl + "/" + dtFileName;
File dtFile = GetFileFromWeb(web, dtFilePath);
if (dtFile == null)
{
// Get the file name from the provided path
Byte[] fileBytes = System.IO.File.ReadAllBytes(localFilePath);
// Use CSOM to upload the file in
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = fileBytes;
newFile.Overwrite = true;
newFile.Url = dtFilePath;
File uploadFile = mpGalleryRoot.Files.Add(newFile);
web.Context.Load(uploadFile);
web.Context.ExecuteQuery();
}
// Grab the file we just uploaded so we can edit its properties
dtFile = GetFileFromWeb(web, dtFilePath);
if (mpGallery.ForceCheckout || mpGallery.EnableVersioning)
{
if (dtFile.CheckOutType == CheckOutType.None)
{
dtFile.CheckOut();
}
}
ListItem fileListItem = dtFile.ListItemAllFields;
string controlContentTypeId = GetContentType(web, mpGallery, "Display Template Code");
fileListItem["Title"] = title;
fileListItem["MasterPageDescription"] = description;
fileListItem["ContentTypeId"] = controlContentTypeId;
fileListItem["TargetControlType"] = ";#Content Web Parts;#";
fileListItem["DisplayTemplateLevel"] = "Item";
fileListItem["TemplateHidden"] = "0";
fileListItem["UIVersion"] = "15";
fileListItem["ManagedPropertyMapping"] = "'Link URL'{Link URL}:'Path','Line 1'{Line 1}:'Title','Line 2'{Line 2}:'','FileExtension','SecondaryFileExtension'";
fileListItem.Update();
if (mpGallery.ForceCheckout || mpGallery.EnableVersioning)
{
dtFile.CheckIn(string.Empty, CheckinType.MajorCheckIn);
if (mpGallery.EnableModeration)
{
dtFile.Approve("");
}
}
web.Context.ExecuteQuery();
Logger.LogSuccessMessage(String.Format("Uploaded Display Template JS File: {0}", dtFile.ServerRelativeUrl), false);
}
catch (Exception ex)
{
Logger.LogErrorMessage(String.Format("UploadDisplayTemplateFileJS() failed for {0}: Error={1}", web.Url, ex.Message), false);
}
}
示例14: AddNewThemeOptionToSite
public static void AddNewThemeOptionToSite(Web web, string themeName, string colorFilePath, string fontFilePath, string backGroundPath, string masterPageName)
{
// Let's get instance to the composite look gallery
List themesOverviewList = web.GetCatalog(124);
web.Context.Load(themesOverviewList);
web.Context.ExecuteQuery();
// Do not add duplicate, if the theme is already there
if (!ThemeEntryExists(web, themesOverviewList, themeName))
{
// if web information is not available, load it
if (!web.IsObjectPropertyInstantiated("ServerRelativeUrl"))
{
web.Context.Load(web);
web.Context.ExecuteQuery();
}
// Let's create new theme entry. Notice that theme selection is not available from UI in personal sites, so this is just for consistency sake
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem item = themesOverviewList.AddItem(itemInfo);
item["Name"] = themeName;
item["Title"] = themeName;
if (!string.IsNullOrEmpty(colorFilePath))
{
item["ThemeUrl"] = URLCombine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", System.IO.Path.GetFileName(colorFilePath)));
}
if (!string.IsNullOrEmpty(fontFilePath))
{
item["FontSchemeUrl"] = URLCombine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", System.IO.Path.GetFileName(fontFilePath)));
}
if (!string.IsNullOrEmpty(backGroundPath))
{
item["ImageUrl"] = URLCombine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", System.IO.Path.GetFileName(backGroundPath)));
}
// we use seattle master if anythign else is not set
if (string.IsNullOrEmpty(masterPageName))
{
item["MasterPageUrl"] = URLCombine(web.ServerRelativeUrl, "/_catalogs/masterpage/seattle.master");
}
else
{
item["MasterPageUrl"] = URLCombine(web.ServerRelativeUrl, string.Format("/_catalogs/masterpage/{0}", Path.GetFileName(masterPageName)));
}
item["DisplayOrder"] = 11;
item.Update();
web.Context.ExecuteQuery();
}
}
示例15: SetThemeToWebImplementation
private static void SetThemeToWebImplementation(this Web web, Web rootWeb, string themeName)
{
LoggingUtility.Internal.TraceInformation((int)EventId.SetTheme, "Setting theme '{0}' for '{1}'", themeName, web.Context.Url);
// Let's get instance to the composite look gallery
List themeList = rootWeb.GetCatalog(124);
rootWeb.Context.Load(themeList);
LoggingUtility.Internal.TraceVerbose("Getting theme list (catalog 124)");
rootWeb.Context.ExecuteQuery();
// Double checking that theme exists
if (rootWeb.ThemeEntryExists(themeName, themeList))
{
CamlQuery query = new CamlQuery();
string camlString = @"
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Name' />
<Value Type='Text'>{0}</Value>
</Eq>
</Where>
</Query>
</View>";
// Let's update the theme name accordingly
camlString = string.Format(camlString, themeName);
query.ViewXml = camlString;
var found = themeList.GetItems(query);
rootWeb.Context.Load(found);
LoggingUtility.Internal.TraceVerbose("Getting theme");
rootWeb.Context.ExecuteQuery();
if (found.Count > 0)
{
ListItem themeEntry = found[0];
//Set the properties for applying custom theme which was just uploaded
string spColorURL = null;
if (themeEntry["ThemeUrl"] != null && themeEntry["ThemeUrl"].ToString().Length > 0)
{
spColorURL = UrlUtility.MakeRelativeUrl((themeEntry["ThemeUrl"] as FieldUrlValue).Url);
}
string spFontURL = null;
if (themeEntry["FontSchemeUrl"] != null && themeEntry["FontSchemeUrl"].ToString().Length > 0)
{
spFontURL = UrlUtility.MakeRelativeUrl((themeEntry["FontSchemeUrl"] as FieldUrlValue).Url);
}
string backGroundImage = null;
if (themeEntry["ImageUrl"] != null && themeEntry["ImageUrl"].ToString().Length > 0)
{
backGroundImage = UrlUtility.MakeRelativeUrl((themeEntry["ImageUrl"] as FieldUrlValue).Url);
}
LoggingUtility.Internal.TraceVerbose("Apply theme '{0}', '{1}', '{2}'.", spColorURL, spFontURL, backGroundImage);
// Set theme for demonstration
// TODO: Why is shareGenerated false? If deploying to root an inheriting, then maybe use shareGenerated = true.
web.ApplyTheme(spColorURL,
spFontURL,
backGroundImage,
false);
web.Context.ExecuteQuery();
LoggingUtility.Internal.TraceVerbose("Theme applied");
// Let's also update master page, if needed
if (themeEntry["MasterPageUrl"] != null && themeEntry["MasterPageUrl"].ToString().Length > 0)
{
var masterUrl = UrlUtility.MakeRelativeUrl((themeEntry["MasterPageUrl"] as FieldUrlValue).Url);
web.SetMasterPageForSiteByUrl(masterUrl);
web.SetCustomMasterPageForSiteByUrl(masterUrl);
}
}
else
{
LoggingUtility.Internal.TraceError((int)EventId.ThemeMissing, "Theme '{0}' not found.", themeName);
}
}
else
{
LoggingUtility.Internal.TraceError((int)EventId.ThemeMissing, "Theme '{0}' does not exist.", themeName);
}
}