本文整理汇总了C#中SPWeb类的典型用法代码示例。如果您正苦于以下问题:C# SPWeb类的具体用法?C# SPWeb怎么用?C# SPWeb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SPWeb类属于命名空间,在下文中一共展示了SPWeb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BatchDeleteItems
public static void BatchDeleteItems(SPList splTask, SPQuery query,SPWeb web)
{
// Set up the variables to be used.
StringBuilder methodBuilder = new StringBuilder();
string batch = string.Empty;
string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Batch onError=\"Return\">{0}</Batch>";
string methodFormat = "<Method ID=\"{0}\">" +
"<SetList Scope=\"Request\">{1}</SetList>" +
"<SetVar Name=\"ID\">{2}</SetVar>" +
"<SetVar Name=\"Cmd\">Delete</SetVar>" +
"</Method>";
// Get the list containing the items to update.
//PList list = WorkFlowUtil.GetWorkflowList(listName);
// Query to get the unprocessed items.
SPListItemCollection unprocessedItems = splTask.GetItems(query);
// Build the CAML delete commands.
foreach (SPListItem item in unprocessedItems)
{
methodBuilder.AppendFormat(methodFormat, "1", item.ParentList.ID, item.ID.ToString());
}
// Put the pieces together.
batch = string.Format(batchFormat, methodBuilder.ToString());
// Process the batch of commands.
string batchReturn = web.ProcessBatchData(batch.ToString());
}
示例2: Get_ZUS_ZD
public static void Get_ZUS_ZD(SPWeb web, int okresId, bool isChorobowa, bool isPracownicy, out double skladkaZD, out DateTime terminPlatnosci, out DateTime terminPrzekazania)
{
skladkaZD = -1;
terminPlatnosci = new DateTime();
terminPrzekazania = new DateTime();
SPList list = web.Lists.TryGetList(targetList);
//if (list != null)
//{
SPListItem item = list.GetItemById(okresId);
if (item != null)
{
Get_ZUS_Terminy(isPracownicy, ref terminPlatnosci, ref terminPrzekazania, item);
//składka zdrowotna
skladkaZD = Double.Parse(item["colZUS_D_ZD_Skladka"].ToString());
}
//}
}
示例3: Send
public void Send(SPWeb web, IEnumerable<string> emailTo, string senderDisplayName, string subject, string body)
{
if (web == null) throw new ArgumentNullException("web");
if (emailTo == null || !emailTo.Any()) throw new ArgumentNullException("emailTo");
var webApplication = web.Site.WebApplication;
var from = new MailAddress(webApplication.OutboundMailSenderAddress, senderDisplayName);
var message = new MailMessage
{
IsBodyHtml = true,
Body = body,
From = from
};
var smtpServer = webApplication.OutboundMailServiceInstance;
var smtp = new SmtpClient(smtpServer.Server.Address);
foreach (var email in emailTo)
{
message.To.Add(email);
}
message.Subject = subject;
smtp.Send(message);
}
示例4: AddNiemUploadEventReceiver
public void AddNiemUploadEventReceiver(SPWeb sysWeb, string spListTitle)
{
SPList spListCustom = null;
spListCustom = sysWeb.Lists.TryGetList(spListTitle);
if (spListCustom != null)
{
// add the TitleFieldUpdateListEventReceiver to specific lists
string assemblyName = "Niem.CaseUpload, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6f7c7006f477a0a5";
string className = "Niem.CaseUpload.NiemUploadCaseHandler.NiemUploadCaseEventHandler";
// When the user is tyring
//SPEventReceiverDefinition erAdding = spListCustom.EventReceivers.Add();
//erAdding.Assembly = assemblyName;
//erAdding.Class = className;
//erAdding.Type = SPEventReceiverType.ItemAdding;
//erAdding.Name = "NiemUploadCaseHandlerEventReceiverItemAdding";
//erAdding.Update();
SPEventReceiverDefinition erUpdating = spListCustom.EventReceivers.Add();
erUpdating.Assembly = assemblyName;
erUpdating.Class = className;
erUpdating.Type = SPEventReceiverType.ItemUpdating;
erUpdating.Name = "NiemUploadCaseHandlerEventReceiverItemUpdating";
erUpdating.Update();
spListCustom.Update();
}
}
示例5: ImportSecurity
public static void ImportSecurity(XmlDocument xmlDoc, bool includeItemSecurity, SPWeb web)
{
Logger.Write("Start Time: {0}.", DateTime.Now.ToString());
foreach (XmlElement listElement in xmlDoc.SelectNodes("//List"))
{
SPList list = null;
try
{
list = web.GetList(web.ServerRelativeUrl.TrimEnd('/') + "/" + listElement.GetAttribute("Url"));
}
catch (ArgumentException) { }
catch (FileNotFoundException) { }
if (list == null)
{
Console.WriteLine("WARNING: List was not found - skipping.");
continue;
}
ImportSecurity(list, web, includeItemSecurity, listElement);
}
Logger.Write("Finish Time: {0}.\r\n", DateTime.Now.ToString());
}
示例6: Create
internal static void Create(SPWeb web, int klientId, int okresId)
{
SPListItem item = tabKlienci.Get_KlientById(web, klientId);
if (item != null)
{
SPFieldLookupValueCollection kody;
switch (item.ContentType.Name)
{
case "Osoba fizyczna":
case "Firma":
kody = new SPFieldLookupValueCollection(item["selSerwisyWspolnicy"].ToString());
break;
default:
kody = new SPFieldLookupValueCollection(item["selSewisy"].ToString());
break;
}
foreach (SPFieldLookupValue kod in kody)
{
switch (kod.LookupValue)
{
case @"PD-M":
Create_PD_M_Form(web, item.ID, okresId);
break;
case @"PD-KW":
Create_PD_KW_Form(web, item.ID, okresId);
break;
default:
break;
}
}
}
}
示例7: GetSitePagesLibrary
public SPList GetSitePagesLibrary(SPWeb web)
{
SPList wikiList;
try
{
string serverRelativeUrl = web.ServerRelativeUrl;
if (serverRelativeUrl == "/")
{
serverRelativeUrl = "/SitePages";
}
else
{
serverRelativeUrl = serverRelativeUrl + "/SitePages";
}
wikiList = web.GetList(serverRelativeUrl);
}
catch
{
wikiList = null;
}
if ((wikiList != null) && (wikiList.BaseTemplate != SPListTemplateType.WebPageLibrary))
{
wikiList = null;
}
return wikiList;
}
示例8: assign_roles
protected void assign_roles(SPWeb web, SPListItem item, SPListItem project, string field_name, string field_guid, SPRoleDefinition definition)
{
try
{
string value = project[field_name].ToString();
SPFieldUserValueCollection field_user_value = (SPFieldUserValueCollection)project.Fields[new Guid(field_guid)].GetFieldValue(value);
foreach (SPFieldUserValue user_value in field_user_value)
{
if (user_value.User == null)
{
SPGroup group = web.SiteGroups.GetByID(user_value.LookupId);
bind_role(item, group, definition);
}
else
{
bind_role(item, user_value.User, definition);
}
}
}
catch (Exception ex)
{
log(web.Site, "为项目【" + project["Title"] + "】的【" + field_name + "】的文档授权时发生错误", "错误", ex.ToString());
}
}
示例9: SendMail
internal static bool SendMail(SPWeb web, System.Net.Mail.MailMessage message)
{
bool result = false;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPWeb web1 = web.Site.OpenWeb())
{
SmtpClient client = new SmtpClient();
client.Host = web1.Site.WebApplication.OutboundMailServiceInstance.Server.Address;
try
{
client.Send(message);
result = true;
}
catch (Exception ex)
{
Logger.LogEvent_Exception(web.Name, ex.ToString());
}
}
});
return result;
}
示例10: BuildFullMenuStructure
private SiteMapNode BuildFullMenuStructure(SPWeb currentWeb)
{
Clear();
SiteMapNode root = null;
SPWeb webSite = SPContext.Current.Site.RootWeb;
string relativeUrl = webSite.ServerRelativeUrl.ToString();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPSite currentsite = new SPSite(webSite.Site.Url);
SPWeb rootweb = currentsite.OpenWeb(relativeUrl);
root = new SiteMapNode(this, rootweb.ID.ToString(), rootweb.ServerRelativeUrl, rootweb.Title);
if (rootweb == currentWeb)
{
SiteMapNode root2 = new SiteMapNode(this, "Root", "/", null);
AddNode(root2);
string cacheKey = rootweb.ID.ToString();
AddMenuToCache(cacheKey, root2);
}
foreach (SPWeb web in rootweb.Webs)
{
SiteMapNode node = BuildNodeTree(web);
AddNode(node, root);
}
});
return root;
}
示例11: 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();
}
示例12: GetCurrentWebSiteLevel
private int GetCurrentWebSiteLevel(SPWeb currentWeb)
{
//We can't really work out the level from the URL because the URL
//might contain managed path that is not part of the site collection
//(e.g. http://server/ or http://server/sites/).
int level = 0;
var tempWeb = currentWeb;
while (!tempWeb.IsRootWeb)
{
level++;
tempWeb = tempWeb.ParentWeb;
//Official guidance from MS is that we do not need to call Dispose on SPWeb.ParentWeb.
}
return level;
}
示例13: GetUserByLoginName
/// <summary>
/// попытка получения пользователя по логину
/// </summary>
/// <param name="loginName"></param>
/// <returns></returns>
public static SPUser GetUserByLoginName(SPWeb web, string loginName)
{
SPUser ret = null;
try
{
PortalSecurity.RunWithElevatedPrivileges(web, (elSite, elWeb) =>
{
ret = elWeb.AllUsers[loginName];
});
}
catch
{
// скорее всего не удалось найти юзвера по логину или логин был без домена, попробуем иначе
try
{
PortalSecurity.RunWithElevatedPrivileges(web, (elSite, elWeb) =>
{
SPPrincipalInfo pinfo = SPUtility.ResolvePrincipal(elWeb,
loginName,
SPPrincipalType.User,
SPPrincipalSource.All,
elWeb.AllUsers, false);
if (pinfo != null && !string.IsNullOrEmpty(pinfo.LoginName))
ret = elWeb.AllUsers[pinfo.LoginName];
});
}
catch { }
}
return ret;
}
示例14: SendMail
public static bool SendMail(
SPWeb web,
MailMessage message,
Models.MailServiceProviders provider = Models.MailServiceProviders.Default)
{
bool result = false;
try
{
switch (provider)
{
case MailServiceProviders.MailGun:
result = Models.MailGun.SendMail(message);
break;
case MailServiceProviders.ElasticEmail:
break;
case MailServiceProviders.SendGrid:
break;
case MailServiceProviders.TurboSMTP:
break;
default:
//wysyłka przez SharePoint
result = Models.LocalSMTP.SendMail(web, message);
break;
}
return result;
}
catch (Exception ex)
{
Logger.LogEvent_Exception(web.Name, ex.ToString());
return false;
}
}
示例15: Ensure
/// <summary>
/// Na podstawie wprowadzonego tematu zadania sprawdza czy istnieje taka procedura, jeżeli nie istnieje to ją dodaje w statusie nowy,
/// jeżeli istnieje i jest zatwierdzona to zwraca jej ID. W pozostałych przypadkach zwraca 0;
/// </summary>
/// <param name="web"></param>
/// <param name="procName"></param>
/// <returns></returns>
public static int Ensure(SPWeb web, string procName, bool ignorujStatusProcedury)
{
SPList list = web.Lists.TryGetList(targetList);
SPListItem item = list.Items.Cast<SPListItem>()
.Where(i => i.Title.Equals(procName))
.FirstOrDefault();
if (item == null)
{
SPListItem newItem = list.AddItem();
newItem["Title"] = procName;
newItem["enumStatusProcedury"] = "Nowa";
newItem.Update();
return newItem.ID;
}
else
{
if (BLL.Tools.Get_Text(item, "enumStatusProcedury").Equals("Zatwierdzona")
|| ignorujStatusProcedury)
{
return item.ID;
}
else return 0;
}
}