本文整理汇总了C#中SPItemEventProperties.OpenWeb方法的典型用法代码示例。如果您正苦于以下问题:C# SPItemEventProperties.OpenWeb方法的具体用法?C# SPItemEventProperties.OpenWeb怎么用?C# SPItemEventProperties.OpenWeb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPItemEventProperties
的用法示例。
在下文中一共展示了SPItemEventProperties.OpenWeb方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSPUserEmailID
/// <summary>
/// Public Methods
/// </summary>
/// <param name="listName"></param>
/// <param name="properties"></param>
/// <param name="fieldName"></param>
/// <returns></returns>
public string GetSPUserEmailID(string listName, SPItemEventProperties properties, string fieldName)
{
SPFieldUser userField = (SPFieldUser)properties.OpenWeb().Lists[listName].Fields.GetField(fieldName);
SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(properties.ListItem[fieldName] + "");
SPUser user = fieldValue.User;
return user.Email;
}
示例2: ItemAdded
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPWeb web = properties.OpenWeb();
string _listName = "Resource_Allocation";
if (properties.ListTitle == "Resource_Allocation")
{
try
{
if (SPUtility.IsEmailServerSet(web))
{
string body = GetParameter("UserContent", properties);
StringDictionary headers = new StringDictionary();
headers.Add("To", GetSPUserEmailID(_listName, properties, "Owner"));
headers.Add("Subject", GetParameter("UserSubject", properties));
headers.Add("Content-Type", "text/html; charset=\"UTF-8\"");
SPUtility.SendEmail(web, headers, body);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
示例3: ItemAdded
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
if (properties.ListTitle == "Terms")
{
Guid siteID, webID, listID;
int itemID;
listID = properties.ListId;
itemID = properties.ListItem.ID;
using (SPWeb web = properties.OpenWeb())
{
siteID = web.Site.ID;
webID = web.ID;
}
//run this block as System Account
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb(webID))
{
web.AllowUnsafeUpdates = true;
SPListItem item = web.Lists[listID].GetItemById(itemID);
if (item != null)
{
if (item["Author"].ToString() == "-1;#")
{
//Impersonate the Author to be System Account
item["Author"] = web.AllUsers[@"SHAREPOINT\system"];
item.SystemUpdate();
}
//start the by add the item and workflow name
StartWorkflow(item, "TERMS_Approval", properties.SiteId);
}
web.AllowUnsafeUpdates = false;
}
}
});
}
else
{
return;
}
}
catch(Exception ex)
{
Common.LogError("TermsEventHandlerEventReceiver.ItemAdded", ex, properties.SiteId);
}
}
示例4: ItemAdded
/// <summary>
/// 已添加项.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
if (properties.ListTitle == "请假单审批任务")
{
Guid related_field_guid = new Guid("{58ddda52-c2a3-4650-9178-3bbc1f6e36da}");
string link = properties.ListItem[related_field_guid].ToString().Split(',')[0];
int id_index = link.IndexOf("ID=");
int id = int.Parse(link.Substring(id_index + 3));
SPListItem ask_leave_item = properties.OpenWeb().Lists["请假单"].GetItemById(id);
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(properties.SiteId))
{
using (SPWeb web = site.OpenWeb("/admin"))
{
SPListItem item = web.Lists[properties.ListId].Items.GetItemById(properties.ListItemId);
item.BreakRoleInheritance(false);
try
{
// 清理旧权限。
int role_index = 0;
while (item.RoleAssignments.Count > 1)
{
SPRoleAssignment role = item.RoleAssignments[role_index];
if (role.Member.LoginName.ToLower() == "sharepoint\\system")
{
role_index++;
}
else
{
item.RoleAssignments.Remove(role_index);
}
}
foreach (SPRoleAssignment ra in ask_leave_item.RoleAssignments)
{
item.RoleAssignments.Add(ra);
}
}
catch (Exception ex)
{
log(site, "自动删除项目旧权限", "错误", ex.ToString());
}
// 分别为各个角色赋予此项目的独特权限:。
log(web.Site, "更新项目权限", "消息", "为项目【" + item["Title"] + "】更新权限完成。");
}
}
});
}
}
示例5: GetParameter
public static string GetParameter(string parameter, SPItemEventProperties properties)
{
string outValue = string.Empty;
SPWeb web = properties.OpenWeb();
SPList list = web.Lists["PhrescoParams"];
SPQuery query = new SPQuery();
query.Query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + parameter + "</Value></Eq></Where>");
var items = list.GetItems(query);
if (items != null && items.Count > 0)
{
outValue = items[0][list.Fields["Value"].InternalName].ToString();
}
return outValue;
}
示例6: CreateDocumentWorkspace
private void CreateDocumentWorkspace(SPItemEventProperties properties)
{
using (SPWeb web = properties.OpenWeb())
using (SPSite site = web.Site)
{
const Int32 LOCALE_ID_ENGLISH = 1033;
SPWebTemplateCollection templates = site.GetWebTemplates(Convert.ToUInt32(LOCALE_ID_ENGLISH));
try
{
SPWebTemplate template = templates["STS#2"];
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(site.ID))
using (SPWeb elevatedWeb = elevatedSite.OpenWeb())
{
SPWeb documentWorkspace = elevatedWeb.Webs.Add(
string.Format("{0}-{1}", properties.List.Title, Guid.NewGuid().ToString()),
properties.ListItem["Title"].ToString(),
string.Format("Document Workspace for {0}", properties.ListItem["Title"].ToString()),
Convert.ToUInt32(LOCALE_ID_ENGLISH),
template,
false, //TODO: This will change to true. We will need custom permissions for each meeting workspace.
false);
properties.ListItem["DocumentWorkspace"] = string.Format("{0}, {1}", documentWorkspace.Url, "Document Workspace");
properties.ListItem.Update();
SetUpDocumentWorkspace(properties, elevatedSite, documentWorkspace);
}
});
}
catch (Exception ex)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception – {0} – {1} – {2}", "Error in Agenda Reciever", ex.Message, ex.StackTrace);
properties.Cancel = true;
properties.ErrorMessage = ex.Message;
}
}
}
示例7: ItemAdded
/// <summary>
/// An item was added
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
// base.ItemAdded(properties);
var currentWeb = properties.OpenWeb();
if (properties.ListTitle == "Proposals")
{
string ProposalID = RemoveNonAlphaAndSpaces(properties.ListItem["Title"].ToString());
string ProposalName = properties.ListItem["Title"].ToString();
properties.ListItem["ClientID"] = ClientID;
properties.ListItem["ProposalID"] = ProposalID;
properties.ListItem.Update();
var redirectToProposalUrl = this.CreateProposalSite(currentWeb, ClientID, ProposalID, ProposalName, properties.ListItem.ID);
SPUtility.Redirect(redirectToProposalUrl, SPRedirectFlags.Default, ctx);
}
}
开发者ID:dreckner,项目名称:RecknerSharePointSolutions,代码行数:25,代码来源:Blueberry_Proposals_List_Event_Receiver.cs
示例8: doit
private void doit(SPItemEventProperties properties)
{
// This is our Context. We get files from it.
SPWeb oWeb = properties.OpenWeb();
// Get the transform.
Stream transformS = GetTransformStream(oWeb);
XslCompiledTransform trans = new XslCompiledTransform();
trans.Load(new XmlTextReader(transformS));
// Create a Temp file to write the result to.
// TODO: Probably could do this in memory with byte[] as they may
// not be that large.
string tempDoc = Path.GetTempFileName();
new FileInfo(tempDoc).Attributes = FileAttributes.Temporary;
FileStream partStream = File.Open(tempDoc, FileMode.Create, FileAccess.Write);
// Get the selected document.
SPFile xml = properties.ListItem.File;
XPathDocument doc = new XPathDocument(xml.OpenBinaryStream());
// Transform the selected document and close.
trans.Transform(doc, null, partStream);
partStream.Close();
// Store the result in the Results Folder
SPFolder resultsfolder = oWeb.GetFolder(ResultsListName);
string filename = getResultsItemNameFromName(xml.Name);
FileStream inStream = File.Open(tempDoc, FileMode.Open, FileAccess.Read);
// We will overwrite the item if it's updating.
resultsfolder.Files.Add(filename, inStream);
// Clean up, delete the temp file.
File.Delete(tempDoc);
}
示例9: CreateMeetingWorkspace
private void CreateMeetingWorkspace(SPItemEventProperties properties)
{
using (SPWeb web = properties.OpenWeb())
using (SPSite site = web.Site)
{
const Int32 LOCALE_ID_ENGLISH = 1033;
SPWebTemplateCollection templates = site.GetWebTemplates(Convert.ToUInt32(LOCALE_ID_ENGLISH));
try
{
SPWebTemplate template = templates["MPS#0"];
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(site.ID))
using (SPWeb elevatedWeb = elevatedSite.OpenWeb())
{
SPWeb meetingWorkspace = elevatedWeb.Webs.Add(
string.Format("{0}-{1}", properties.List.Title,
Guid.NewGuid().ToString()),
properties.ListItem["Title"].ToString(),
properties.ListItem["Location"].ToString(),
Convert.ToUInt32(LOCALE_ID_ENGLISH),
template,
false, //TODO: This will change to true. We will need custom permissions for each meeting workspace.
false);
SPMeeting meeting = SPMeeting.GetMeetingInformation(meetingWorkspace);
meeting.LinkWithEvent(web,
properties.ListId.ToString(),
properties.ListItemId,
"WorkspaceLink",
"Workspace");
meetingWorkspace.AllowUnsafeUpdates = true;
string currentTheme = web.Theme;
meetingWorkspace.ApplyTheme(currentTheme);
//Add the DocumentSet content Type to 'Document Library'
SPList documentLibrary = meetingWorkspace.Lists["Document Library"];
documentLibrary.ContentTypes.Add(site.RootWeb.ContentTypes["Document Set"]);
documentLibrary.Update();
//Remove the Objectives List and Attendees List from meeting workspace
SPList objectivesList = meetingWorkspace.Lists["Objectives"];
SPList attendeesList = meetingWorkspace.Lists["Attendees"];
meetingWorkspace.Lists.Delete(objectivesList.ID);
attendeesList.Hidden = true;
attendeesList.Update();
//Hide the webpart
SPLimitedWebPartManager webPartManager = meetingWorkspace.GetLimitedWebPartManager("Default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
for (int k = 0; k < webPartManager.WebParts.Count; k++)
{
//get reference to webpart
WebPart wp = webPartManager.WebParts[k] as WebPart;
webPartManager.DeleteWebPart(webPartManager.WebParts[k]);
//update spWeb object
meetingWorkspace.Update();
}
//Add the extra fields to the Agenda List
SPList meetingAgendaList = meetingWorkspace.Lists["Agenda"];
SPField ownerField = meetingAgendaList.Fields["Owner"];
SPField timeField = meetingAgendaList.Fields["Time"];
ownerField.Title = "Presenter";
timeField.Title = "Time (in minutes)";
ownerField.Update();
timeField.Update();
SPField fldSponsor = meetingAgendaList.Fields.CreateNewField(SPFieldType.User.ToString(), "Sponsor");
SPField fldItemNumber = meetingAgendaList.Fields.CreateNewField(SPFieldType.Number.ToString(), "Item Number");
SPField fldOffice = meetingAgendaList.Fields.CreateNewField(SPFieldType.Text.ToString(), "Office");
SPField fldAgendaID = meetingAgendaList.Fields.CreateNewField(SPFieldType.Number.ToString(), "AgendaID");
SPField fldDocuments = meetingAgendaList.Fields.CreateNewField(SPFieldType.URL.ToString(), "Documents");
meetingAgendaList.Fields.Add(fldSponsor);
meetingAgendaList.Fields.Add(fldItemNumber);
meetingAgendaList.Fields.Add(fldOffice);
meetingAgendaList.Fields.Add(fldDocuments);
meetingAgendaList.Fields.Add(fldAgendaID);
meetingAgendaList.Update();
SPView defaultView = meetingAgendaList.Views["All Items"];
SPViewFieldCollection viewFields = defaultView.ViewFields;
viewFields.Add(meetingAgendaList.Fields["Sponsor"]);
viewFields.Add(meetingAgendaList.Fields["Item Number"]);
viewFields.Add(meetingAgendaList.Fields["Office"]);
viewFields.Add(meetingAgendaList.Fields["Documents"]);
defaultView.Update();
meetingWorkspace.Update();
meetingWorkspace.AllowUnsafeUpdates = false;
//.........这里部分代码省略.........
示例10: findSimilarFiles
static List<LDwithID> findSimilarFiles(SPItemEventProperties properties)
{
SPWeb myWeb = properties.OpenWeb();
List<long> cFiles = new List<long>();
List<LDwithID> similarResults = new List<LDwithID>();
SPList currentList = properties.List;
SPListItem currentItem = properties.ListItem;
SPAttachmentCollection curFiles = currentItem.Attachments;
try
{
foreach (String attachmentname in curFiles)
{
String attachmentAbsoluteURL = currentItem.Attachments.UrlPrefix + attachmentname;
SPFile attachmentFile = myWeb.GetFile(attachmentAbsoluteURL);
cFiles.Add(attachmentFile.Length);
}
if (cFiles.Count > 0)
{
SPListItemCollection items = properties.List.Items;
foreach (SPListItem item in items)
{
if (item.ID != currentItem.ID)
{
SPAttachmentCollection files = item.Attachments;
if (files.Count > 0)
{
foreach (String file in files)
{
try
{
String attachmentAbsoluteURL = currentItem.Attachments.UrlPrefix + file;
SPFile attachmentFile = myWeb.GetFile(attachmentAbsoluteURL);
foreach (long cFile in cFiles)
{
if (attachmentFile.Length == cFile)
similarResults.Add(new LDwithID { recId = item.ID.ToString(), Distance = 99 });
if (similarResults.Count > 1) return similarResults;
}
}
catch { }
}
}
}
}
}
}
catch { }
return similarResults;
}
示例11: ExecuteReceivedEvent
private void ExecuteReceivedEvent(AlertEventType eventType, SPItemEventProperties properties)
{
LogManager.write("Entered in to ExecuteReceivedEvent with event type" + eventType);
try
{
using (SPWeb web = properties.OpenWeb())
{
//TODO we have to check is feature activated for this site or not
AlertManager alertManager = new AlertManager(web.Site.Url);
MailTemplateManager mailTemplateManager = new MailTemplateManager(web.Site.Url);
IList<Alert> alerts = alertManager.GetAlertForList(properties.ListItem ,eventType, mailTemplateManager);
Notifications notifications = new Notifications();
foreach (Alert alert in alerts)
{
if (eventType != AlertEventType.DateColumn)
{
if (alert.IsValid(properties.ListItem, eventType, properties))
{
try
{
if (alert.SendType == SendType.ImmediateAlways)
{
notifications.SendMail(alert, eventType, properties.ListItem, FinalBody);
}
else if (alert.SendType == SendType.ImmediateBusinessDays)
{
if (alert.ImmediateBusinessDays.Contains((WeekDays)DateTime.UtcNow.DayOfWeek))
{
if (alert.BusinessStartHour <= Convert.ToInt32(DateTime.UtcNow.Hour) && alert.BusinessendtHour >= Convert.ToInt32(DateTime.UtcNow.Hour))
{
notifications.SendMail(alert, eventType, properties.ListItem, FinalBody);
}
else
{
return;
}
}
}
else
{
CreateDelayedAlert(alert, eventType, properties, alertManager);
}
}
catch { }
}
}
}
}
}
catch (System.Exception Ex)
{
LogManager.write("Error occured white excuting event receiver" + Ex.Message);
}
}
示例12: ItemDeleting
/// <summary>
/// An item is being deleted
/// </summary>
public override void ItemDeleting(SPItemEventProperties properties)
{
base.ItemDeleting(properties);
if (properties.ListTitle == "Proposals")
{
if (properties.ListItem["ClientID"] != null && properties.ListItem["ProposalID"] != null) {
var deletingClientID = properties.ListItem["ClientID"].ToString();
var deletingProposalID = properties.ListItem["ProposalID"].ToString();
if (deletingClientID != string.Empty && deletingProposalID != string.Empty)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
var currentWeb = properties.OpenWeb();
SPWeb clientWeb = currentWeb.Webs[deletingClientID];
var deletingWeb = clientWeb.Webs[deletingProposalID];
if (deletingWeb.Exists)
{
clientWeb.Webs.Delete(deletingProposalID);
}
});
}
}
}
}
开发者ID:dreckner,项目名称:RecknerSharePointSolutions,代码行数:40,代码来源:Blueberry_Proposals_List_Event_Receiver.cs
示例13: ItemUpdating
/// <summary>
/// An item is being updated
/// </summary>
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
if (properties.ListTitle == "Proposals")
{
if (properties.ListItem["ClientID"] != null && properties.ListItem["ProposalID"] != null)
{
string afterValue = "";
string afterValueID = "";
var updatingClientID = properties.ListItem["ClientID"].ToString();
var ProposalName = properties.ListItem["Title"].ToString();
if (properties.AfterProperties["Title"] != null) {
afterValue = properties.AfterProperties["Title"].ToString();
afterValueID = RemoveNonAlphaAndSpaces(afterValue);
var updatingProposalID = RemoveNonAlphaAndSpaces(ProposalName);
if (updatingClientID != string.Empty && updatingProposalID != string.Empty)
{
if (afterValueID != string.Empty)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
var currentWeb = properties.OpenWeb();
SPWeb clientWeb = currentWeb.Webs[updatingClientID];
var updatingWeb = clientWeb.Webs[updatingProposalID];
if (updatingWeb.Exists)
{
updatingWeb.Name = afterValueID;
updatingWeb.Title = afterValue;
updatingWeb.Update();
}
});
}
}
}
}
}
}
开发者ID:dreckner,项目名称:RecknerSharePointSolutions,代码行数:56,代码来源:Blueberry_Proposals_List_Event_Receiver.cs