本文整理汇总了C#中SPWeb.GetCatalog方法的典型用法代码示例。如果您正苦于以下问题:C# SPWeb.GetCatalog方法的具体用法?C# SPWeb.GetCatalog怎么用?C# SPWeb.GetCatalog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPWeb
的用法示例。
在下文中一共展示了SPWeb.GetCatalog方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWebPart
public static System.Web.UI.WebControls.WebParts.WebPart CreateWebPart(SPWeb web, string webPartName, SPLimitedWebPartManager webPartManager)
{
SPQuery qry = new SPQuery();
qry.Query = String.Format(CultureInfo.CurrentCulture,
"<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>{0}</Value></Eq></Where>",
webPartName);
SPList webPartGallery = null;
if (null == web.ParentWeb)
{
webPartGallery = web.GetCatalog(SPListTemplateType.WebPartCatalog);
}
else
{
webPartGallery = web.Site.RootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
}
SPListItemCollection webParts = webPartGallery.GetItems(qry);
XmlReader xmlReader = new XmlTextReader(webParts[0].File.OpenBinaryStream());
string errorMsg;
System.Web.UI.WebControls.WebParts.WebPart webPart = webPartManager.ImportWebPart(xmlReader, out errorMsg);
return webPart;
}
示例2: UpdateCurrentComposedLookItem
private static void UpdateCurrentComposedLookItem(SPWeb web, ComposedLook composedLook)
{
var catalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
var items = catalog.GetItems(new SPQuery
{
RowLimit = 1u,
Query = "<Where><Eq><FieldRef Name='DisplayOrder'/><Value Type='Number'>0</Value></Eq></Where>",
ViewFields = "<FieldRef Name='DisplayOrder'/>",
ViewFieldsOnly = true
});
// Delete current composed look item
if (items.Count == 1)
{
items[0].Delete();
}
// Create the new composed look item
var item = catalog.AddItem();
item[BuiltInFields.DisplayOrderName] = 0;
item[SPBuiltInFieldId.Name] = SPResource.GetString(web.UICulture, "DesignGalleryCurrentItemName");
item[SPBuiltInFieldId.Title] = SPResource.GetString(web.UICulture, "DesignGalleryCurrentItemName");
item[BuiltInFields.MasterPageUrlName] = HttpUtility.UrlDecode(new Uri(composedLook.MasterPagePath.Url).AbsolutePath);
item[BuiltInFields.ThemeUrlName] = HttpUtility.UrlDecode(new Uri(composedLook.ThemePath.Url).AbsolutePath);
item[BuiltInFields.ImageUrlName] = composedLook.ImagePath == null ? string.Empty : HttpUtility.UrlDecode(new Uri(composedLook.ImagePath.Url).AbsolutePath);
item[BuiltInFields.FontSchemeUrlName] = HttpUtility.UrlDecode(new Uri(composedLook.FontSchemePath.Url).AbsolutePath);
item.Update();
}
示例3: Create
/// <summary>
/// Creates the specified composed look.
/// </summary>
/// <param name="web">The web.</param>
/// <param name="entity">The entity.</param>
/// <returns>
/// The newly created composed look.
/// </returns>
public ComposedLook Create(SPWeb web, ComposedLook entity)
{
var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
var item = designCatalog.Items.Add();
this._binder.FromEntity(entity, item);
item.Update();
return this._binder.Get<ComposedLook>(item);
}
示例4: GetByName
/// <summary>
/// Retrieves a composed look by name.
/// </summary>
/// <param name="web">The current web.</param>
/// <param name="name">The name of the composed look.</param>
/// <returns>
/// Returns a composed look by name.
/// </returns>
public ComposedLook GetByName(SPWeb web, string name)
{
var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
var items = designCatalog.GetItems(new SPQuery()
{
RowLimit = 1u,
ViewFields = @"
<FieldRef Name=""Name"" />
<FieldRef Name=" + BuiltInFields.MasterPageUrlName + @" />
<FieldRef Name=" + BuiltInFields.ThemeUrlName + @" />
<FieldRef Name=" + BuiltInFields.ImageUrlName + @" />
<FieldRef Name=" + BuiltInFields.FontSchemeUrlName + @" />",
Query = @"
<Where>
<Eq>
<FieldRef Name=""Name"" />
<Value Type=""Text"">" + name + @"</Value>
</Eq>
</Where>"
});
return items.Count != 1 ? null : this._binder.Get<ComposedLook>(items[0]);
}
示例5: CreateDefaultWebPart
//public virtual void ExportWebPart(WebPart webPart, XmlWriter writer)
//{
// if (webPart == null)
// {
// throw new ArgumentNullException("webPart");
// }
// if (!this.Controls.Contains(webPart))
// {
// throw new ArgumentException(SR.GetString("UnknownWebPart"), "webPart");
// }
// if (writer == null)
// {
// throw new ArgumentNullException("writer");
// }
// if (webPart.ExportMode == WebPartExportMode.None)
// {
// throw new ArgumentException(SR.GetString("WebPartManager_PartNotExportable"), "webPart");
// }
// bool arg_79_0 = (webPart.ExportMode != WebPartExportMode.NonSensitiveData) ? false : (this.Personalization.Scope != PersonalizationScope.Shared);
// bool flag = arg_79_0;
// writer.WriteStartElement("webParts");
// writer.WriteStartElement("webPart");
// writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/WebPart/v3");
// writer.WriteStartElement("metaData");
// writer.WriteStartElement("type");
// Control control = webPart.ToControl();
// UserControl userControl = control as UserControl;
// if (userControl == null)
// {
// writer.WriteAttributeString("name", WebPartUtil.SerializeType(control.GetType()));
// }
// else
// {
// writer.WriteAttributeString("src", userControl.AppRelativeVirtualPath);
// }
// writer.WriteEndElement();
// writer.WriteElementString("importErrorMessage", webPart.ImportErrorMessage);
// writer.WriteEndElement();
// writer.WriteStartElement("data");
// IDictionary personalizablePropertyValues = PersonalizableAttribute.GetPersonalizablePropertyValues(webPart, PersonalizationScope.Shared, flag);
// writer.WriteStartElement("properties");
// if (!(webPart is GenericWebPart))
// {
// this.ExportIPersonalizable(writer, webPart, flag);
// this.ExportToWriter(personalizablePropertyValues, writer);
// }
// else
// {
// this.ExportIPersonalizable(writer, control, flag);
// IDictionary personalizablePropertyValues2 = PersonalizableAttribute.GetPersonalizablePropertyValues(control, PersonalizationScope.Shared, flag);
// this.ExportToWriter(personalizablePropertyValues2, writer);
// writer.WriteEndElement();
// writer.WriteStartElement("genericWebPartProperties");
// this.ExportIPersonalizable(writer, webPart, flag);
// this.ExportToWriter(personalizablePropertyValues, writer);
// }
// writer.WriteEndElement();
// writer.WriteEndElement();
// writer.WriteEndElement();
// writer.WriteEndElement();
//}
private static void CreateDefaultWebPart(SPWeb web, SPLimitedWebPartManager webPartManager, WebpartDefinition wp, System.Web.UI.WebControls.WebParts.WebPart concerateWP)
{
//TODO : find a solution to create default webpart late
return;
if (wp is XSLTListViewWP)
{
XSLTListViewWP xstlWP = wp as XSLTListViewWP;
if (xstlWP.CreateDefaultWP)
{
using (MemoryStream ms = new MemoryStream())
{
XmlWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
concerateWP.ExportMode = System.Web.UI.WebControls.WebParts.WebPartExportMode.All;
webPartManager.ExportWebPart(concerateWP, writer);
var webPartGallery = web.GetCatalog(SPListTemplateType.WebPartCatalog);
//var fileStream
SPFile spfile = webPartGallery.RootFolder.Files.Add(wp.Title + ".webpart", ms.GetBuffer(), true);
// Commit
webPartGallery.RootFolder.Update();
webPartGallery.Update();
}
}
}
}
示例6: CreateWebPart
public static WebPart CreateWebPart(SPWeb web, string webPartName)
{
var query = new SPQuery
{
Query =
String.Format(
"<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='string'>{0}</Value></Eq></Where>",
webPartName)
};
SPList webPartGallery = web.ParentWeb == null ? web.GetCatalog(SPListTemplateType.WebPartCatalog) : web.ParentWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
SPListItemCollection webParts = webPartGallery.GetItems(query);
if (webParts.Count > 0)
{
string typeName = webParts[0].GetFormattedValue("ows_WebPartTypeName");
string assemblyName = webParts[0].GetFormattedValue("ows_WebPartAssembly");
if (assemblyName != "")
{
System.Runtime.Remoting.ObjectHandle webPartHandle = Activator.CreateInstance(assemblyName, typeName);
{
var webPart = (WebPart)webPartHandle.Unwrap();
webPart.Title = webPartName;
return webPart;
}
}
return null;
}
return null;
}
示例7: Update
/// <summary>
/// Updates the specified composed look.
/// </summary>
/// <param name="web">The web.</param>
/// <param name="entity">The entity.</param>
public void Update(SPWeb web, ComposedLook entity)
{
var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
var item = designCatalog.Items.GetItemById(entity.Id);
this._binder.FromEntity(entity, item);
item.Update();
}
示例8: GetById
/// <summary>
/// Gets the composed look by id.
/// </summary>
/// <param name="web">The web.</param>
/// <param name="id">The id.</param>
/// <returns>The composed look.</returns>
public ComposedLook GetById(SPWeb web, int id)
{
var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
var composedLook = this._binder.Get<ComposedLook>(designCatalog.GetItemById(id));
return DecodeUrls(composedLook);
}
示例9: Delete
/// <summary>
/// Deletes the specified composed look.
/// </summary>
/// <param name="web">The web.</param>
/// <param name="entity">The entity.</param>
public void Delete(SPWeb web, ComposedLook entity)
{
var designCatalog = web.GetCatalog(SPListTemplateType.DesignCatalog);
var item = designCatalog.GetItemById(entity.Id);
item.Delete();
}