protected static async Task copyTemplatesAsync(Guid siteId, Guid webId, Guid listId, int itemId, SPUserToken userToken, bool addTemplates, bool isProtected) { await Task.Run(() => { using (SPSite qSite = new SPSite(siteId, userToken)) using (SPWeb qWeb = qSite.OpenWeb(webId)) { SPList qList = qWeb.Lists[listId]; SPListItem qBriefingItem = qList.GetItemById(itemId); string folderUrl = Config.System.RootWebBriefingTemplatesFolder; if (addTemplates && folderUrl != null) { SPFolder bfTemplateFolder = qWeb.ParentWeb.GetFolder(SPUrlUtility.CombineUrl(qWeb.ParentWeb.Url, folderUrl)); copyTemplates(bfTemplateFolder, qBriefingItem.Folder, isProtected); } string libraryUrl = Config.System.CurrentWebBriefingTemplatesLibrary; if (libraryUrl != null) { SPFolder briefingFolder = qBriefingItem.Folder; if (addTemplates) { SPList bfTemplateLibrary = qWeb.GetList(SPUrlUtility.CombineUrl(qWeb.Url, libraryUrl)); copyTemplates(bfTemplateLibrary.RootFolder, briefingFolder, isProtected); } List <SPContentType> contenttypes = new List <SPContentType>(); contenttypes.Add(qBriefingItem.ParentList.ContentTypes["Document"]); briefingFolder.UniqueContentTypeOrder = contenttypes; briefingFolder.Update(); } } }); }
private static void copyBriefingFiles(SPFolder sourceFolder, SPFolder destinationFolder) { foreach (SPFile f in sourceFolder.Files) { if (f.Exists && !f.Name.EndsWith(".aspx", StringComparison.InvariantCultureIgnoreCase)) { var templatefile = f.OpenBinaryStream(SPOpenBinaryOptions.SkipVirusScan); var file = destinationFolder.Files.Add(SPUrlUtility.CombineUrl(destinationFolder.ServerRelativeUrl, f.Name), templatefile, true); if (file.CheckOutType != SPFile.SPCheckOutType.None) { file.CheckIn(""); } } } foreach (SPFolder folder in sourceFolder.SubFolders) { if (folder.Item != null && folder.Name != "Forms") { SPFolder fld = destinationFolder.SubFolders.Add(folder.Name); copyBriefingFiles(folder, fld); } } }
public static SPListItemCollection getPreviouslySavedObjectives(string strEmpDisplayName, string Active_Set_Goals_Year) { SPListItemCollection listItems = null; SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "Objectives")); if (spList != null) { SPQuery qry = new SPQuery(); qry.Query = @" <Where> <And> <Eq> <FieldRef Name='Emp' /> <Value Type='User'>" + strEmpDisplayName + @"</Value> </Eq> <Eq> <FieldRef Name='ObjYear' /> <Value Type='Text'>" + Active_Set_Goals_Year + @"</Value> </Eq> </And> </Where>"; listItems = spList.GetItems(qry); DataTable test = listItems.GetDataTable(); } }); return(listItems); }
public static void Update_Objectives(string columnToBeUpdated, DataTable tblObjectives) { SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); spWeb.AllowUnsafeUpdates = true; SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "Objectives")); if (tblObjectives != null) { foreach (DataRow row in tblObjectives.Rows) { SPListItem oListItem = spList.GetItemById(int.Parse(row["ID"].ToString())); oListItem[columnToBeUpdated] = row[columnToBeUpdated].ToString(); oListItem.Update(); } } else { } spWeb.AllowUnsafeUpdates = false; }); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; if (site != null) { SPWeb web = site.RootWeb; SPList mpGallery = web.GetCatalog(SPListTemplateType.MasterPageCatalog); string xapFileUrl = SPUrlUtility.CombineUrl(mpGallery.RootFolder.Url, "Chapter10.Silverlight.xap"); SPFile file = web.GetFile(xapFileUrl); if (file.Exists && file.Level != SPFileLevel.Published) { if (file.CheckOutType != SPFile.SPCheckOutType.None) { file.CheckIn("Checked in during feature activation", SPCheckinType.MajorCheckIn); } if (file.Level != SPFileLevel.Published) { file.Approve("Approved during feature activation"); } } } }
protected override void CreateChildControls() { if (!this.error) { try { base.CreateChildControls(); if (!string.IsNullOrEmpty(this.DotUrl) && !string.IsNullOrEmpty(this.DotUrl.Trim())) { var img = new Image(); img.ID = "imgGraph"; string url = SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, Utils.GetHandlerRelativeUrl(this.DotUrl.Trim(), this.ImageType, this.LayoutType)); img.ImageUrl = url; if (!string.IsNullOrEmpty(this.ImageCssClass) && !string.IsNullOrEmpty(this.ImageCssClass.Trim())) { img.CssClass = this.ImageCssClass; } this.Controls.Add(img); } } catch (Exception x) { this.handleException(x); } } }
private SPList GetSpList(MethodInfo method) { string propName = method.Name.Substring(4); var prop = method.DeclaringType.GetProperty(propName); var listAttr = (ListAttribute)Attribute.GetCustomAttribute(prop, typeof(ListAttribute)); if (listAttr == null) { return(_queryWeb.Web.Lists[method.Name]); } if (listAttr.Name != null) { return(_queryWeb.Web.Lists[listAttr.Name]); } if (listAttr.Url != null) { var url = SPUrlUtility.CombineUrl(_queryWeb.Web.ServerRelativeUrl, listAttr.Url); return(_queryWeb.Web.GetList(url)); } if (listAttr.Id != null) { return(_queryWeb.Web.Lists[new Guid(listAttr.Id)]); } throw new SharepointCommonException(string.Format("Unable find list for property {0}", method.Name)); }
public static SPList TryGetListByUrl(SPWeb web, string listUrlName) { string webRelativeUrl = web.ServerRelativeUrl; string listRelativeUrl = String.Empty; string listDocRelativeUrl = String.Empty; SPList list = null; listRelativeUrl = ("/Lists/" + listUrlName); listDocRelativeUrl = ("/" + listUrlName); string listWebRelativeUrl = SPUrlUtility.CombineUrl(webRelativeUrl, listRelativeUrl); string listDocWebRelativeUrl = SPUrlUtility.CombineUrl(webRelativeUrl, listDocRelativeUrl); try { list = web.GetList(listWebRelativeUrl); } catch { } if (list != null) { return(list); } try { list = web.GetList(listDocWebRelativeUrl); } catch { } return(list); }
public static SPList TryGetListByUrl(SPWeb web, string listUrlName, SPBaseType baseType) { string WebRelativeUrl = web.ServerRelativeUrl; string ListRelativeUrl = String.Empty; SPList list = null; if (baseType == SPBaseType.GenericList) { ListRelativeUrl = ("/Lists/" + listUrlName); } else { ListRelativeUrl = ("/" + listUrlName); } string ListWebRelativeUrl = SPUrlUtility.CombineUrl(WebRelativeUrl, ListRelativeUrl); try { list = web.GetList(ListWebRelativeUrl); } catch { } return(list); }
public static SPListItemCollection get_Active_Years() { SPListItemCollection listItems = null; SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "EPMYear")); //SPList spList = spWeb.GetList("/Lists/EPMYear"); if (spList != null) { SPQuery qry = new SPQuery(); qry.Query = @" <Where> <Eq> <FieldRef Name='State' /> <Value Type='Choice'>مفعل</Value> </Eq> </Where>"; qry.ViewFieldsOnly = true; qry.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='Year' /><FieldRef Name='State' />"; listItems = spList.GetItems(qry); } }); return(listItems); }
public static void Update_Year(string mode, string year, string new_state) { SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); spWeb.AllowUnsafeUpdates = true; SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "EPMYear")); //SPList oList = oWeb.GetList("/Lists/EPMYear"); SPQuery qry = new SPQuery(); qry.Query = @" <Where> <Eq> <FieldRef Name='Title' /> <Value Type='Text'>" + mode + @"</Value> </Eq> </Where>"; SPListItemCollection listItems = spList.GetItems(qry); SPListItem itemToUpdate = spList.GetItemById(listItems[0].ID); itemToUpdate["Year"] = year; itemToUpdate["State"] = new_state; itemToUpdate.Update(); spWeb.AllowUnsafeUpdates = false; }); }
private void getPreviouslySavedObjectives() { SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "Objectives")); //SPList spList = spWeb.GetList("/Lists/Objectives"); SPQuery qry = new SPQuery(); qry.Query = @" <Where> <And> <Eq> <FieldRef Name='Emp' /> <Value Type='User'>" + strEmpDisplayName + @"</Value> </Eq> <Eq> <FieldRef Name='ObjYear' /> <Value Type='Text'>" + Active_Rate_Goals_Year + @"</Value> </Eq> </And> </Where>"; qry.ViewFieldsOnly = true; qry.ViewFields = @"<FieldRef Name='ID' /><FieldRef Name='ObjName' /><FieldRef Name='ObjYear' /><FieldRef Name='ObjWeight' /><FieldRef Name='AccPercent' />"; SPListItemCollection listItems = spList.GetItems(qry); tblObjectives = listItems.GetDataTable(); }); }
public static string getPreviouslySavedNote1(string strEmpDisplayName, string Active_Rate_Goals_Year) { string Note1 = string.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "ObjsRatingNotesByEmp")); if (spList != null) { SPQuery qry = new SPQuery(); qry.Query = @" <Where> <And> <Eq> <FieldRef Name='Emp' /> <Value Type='User'>" + strEmpDisplayName + @"</Value> </Eq> <Eq> <FieldRef Name='ObjsYear' /> <Value Type='Text'>" + Active_Rate_Goals_Year + @"</Value> </Eq> </And> </Where>"; SPListItemCollection results = spList.GetItems(qry); if (results.Count > 0) { Note1 = results[0]["Note1"]?.ToString() ?? ""; } } }); return(Note1); }
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel) { base.ProcessWebpartProperties(webpartInstance, webpartModel); var typedWebpart = webpartInstance.WithAssertAndCast <ListViewWebPart>("webpartInstance", value => value.RequireNotNull()); var typedModel = webpartModel.WithAssertAndCast <ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull()); var web = _host.SPLimitedWebPartManager.Web; SPList list = null; if (typedModel.ListId.HasValue) { list = web.Lists[typedModel.ListId.Value]; } else if (!string.IsNullOrEmpty(typedModel.ListUrl)) { list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl)); } else if (!string.IsNullOrEmpty(typedModel.ListTitle)) { list = web.Lists.TryGetList(typedModel.ListTitle); } typedWebpart.ListName = list.ID.ToString(); typedWebpart.ListId = list.ID; typedWebpart.TitleUrl = list.DefaultViewUrl; }
public static SPFile CopyFile(SPFile sourceFile, SPFolder targetFolder, bool overwrite = false) { SPFile newFile; using (Stream stream = sourceFile.OpenBinaryStream()) { string fileName = SPUrlUtility.CombineUrl(targetFolder.ServerRelativeUrl, sourceFile.Name); bool crossSite = (sourceFile.Web.Site.ID != targetFolder.ParentWeb.Site.ID); SPUser author; SPUser editor; if (crossSite) { author = targetFolder.ParentWeb.EnsureUser(sourceFile.Author.LoginName); editor = targetFolder.ParentWeb.EnsureUser(sourceFile.ModifiedBy.LoginName); } else { author = sourceFile.Author; editor = sourceFile.ModifiedBy; } newFile = targetFolder.Files.Add( fileName, stream, sourceFile.Properties, author, editor, sourceFile.TimeCreated, sourceFile.TimeLastModified, sourceFile.CheckInComment, overwrite); } return(newFile); }
protected SPWeb GetWeb(SPWeb parentWeb, WebDefinition webModel) { var newWebSiteRelativeUrl = SPUrlUtility.CombineUrl(parentWeb.ServerRelativeUrl, webModel.Url); var currentWeb = parentWeb.Site.OpenWeb(newWebSiteRelativeUrl); return(currentWeb); }
/// <summary> /// Stores the hash for the specified file. /// </summary> /// <param name="contextManager">Provides the current SharePoint context</param> /// <param name="logger">To log messages to the migrator</param> /// <param name="prefixedServerRelativeUrl">Server relative URL of the file; a prefixed URL is allowed</param> /// <param name="hash">Hash value to store</param> public void StoreFileHash(IContextManager contextManager, IUpgradeLog logger, string prefixedServerRelativeUrl, byte[] hash) { if (_hashValues == null) { throw new InvalidOperationException("Must have been initialized first (by calling GetFileHash)"); } var clientContext = contextManager.CurrentContext; var serverRelativeUrl = SPUrlUtility.ResolveServerRelativeUrl(clientContext.Site, clientContext.Web, prefixedServerRelativeUrl); var webRelativeUrl = serverRelativeUrl.Substring(clientContext.Web.ServerRelativeUrl.Length); if (webRelativeUrl.StartsWith("/")) { webRelativeUrl = webRelativeUrl.Substring(1); } var hashString = BitConverter.ToString(hash); _hashValues[webRelativeUrl] = hashString; var propertyValue = JsonConvert.SerializeObject(_hashValues.ToList()); clientContext.Web.AllProperties[_propertyBagKey] = propertyValue; clientContext.Web.Update(); clientContext.ExecuteQuery(); }
public static SPList GetListByUrl(this SPWeb web, string listUrl) { if (string.IsNullOrEmpty(listUrl)) { throw new ArgumentNullException("listUrl"); } Uri uri = new Uri(listUrl, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri /*SPUrlUtility.IsUrlRelative(listUrl)*/) { string relativeListUrl = string.Concat("/", listUrl.TrimStart('/')); relativeListUrl = relativeListUrl.StartsWith(web.ServerRelativeUrl) ? relativeListUrl : SPUrlUtility.CombineUrl(web.ServerRelativeUrl, relativeListUrl); if (relativeListUrl == web.ServerRelativeUrl) { throw new SPException("List does not exist."); } return(web.GetList(relativeListUrl)); } if (listUrl.TrimEnd('/') == web.Url) { throw new SPException("List does not exist."); } return(web.GetList(listUrl)); }
/// <summary> /// Gets the hash for the specified file. /// </summary> /// <param name="contextManager">Provides the current SharePoint context</param> /// <param name="logger">To log messages to the migrator</param> /// <param name="prefixedServerRelativeUrl">Server relative URL of the file; a prefixed URL is allowed.</param> /// <returns>The stored hash, or an empty array if there is no stored hash</returns> public byte[] GetFileHash(IContextManager contextManager, IUpgradeLog logger, string prefixedServerRelativeUrl) { if (_hashValues == null) { InitHashValues(contextManager, logger); } var clientContext = contextManager.CurrentContext; var serverRelativeUrl = SPUrlUtility.ResolveServerRelativeUrl(clientContext.Site, clientContext.Web, prefixedServerRelativeUrl); var webRelativeUrl = serverRelativeUrl.Substring(clientContext.Web.ServerRelativeUrl.Length); if (webRelativeUrl.StartsWith("/")) { webRelativeUrl = webRelativeUrl.Substring(1); } var hash = new List <byte>(); var hashString = ""; if (_hashValues.TryGetValue(webRelativeUrl, out hashString)) { var parts = hashString.Split('-'); foreach (var part in parts) { hash.Add(byte.Parse(part, System.Globalization.NumberStyles.HexNumber)); } } return(hash.ToArray()); }
/// <summary> /// Extension to <see cref="SPUtility.GetServerRelativeUrlFromPrefixedUrl"/>. /// This method supports two more tokens. "~variation/" will be resolved to the top web of the current variation; /// where "~pages/" will be resolved to the name of publishing page library under the locale of the current variation. /// It also allows to specify the returned URL to be server-relative or absolute. /// </summary> /// <param name="value">Input URL.</param> /// <param name="uriKind">Format of the resolved URL.</param> /// <returns>Resolved URL.</returns> public static string ResolvePrefixedUrl(string value, UriKind uriKind) { if (SPContext.Current != null) { string resolvedPath; if (value.StartsWith("~variation/", StringComparison.OrdinalIgnoreCase)) { resolvedPath = SPUrlUtility.CombineUrl(VariationContext.Current.TopWebServerRelativeUrl, value.Substring(11)); int pagesPos = resolvedPath.IndexOf("~pages/", 0, StringComparison.OrdinalIgnoreCase); if (pagesPos >= 0) { resolvedPath = String.Concat(resolvedPath.Substring(0, pagesPos), VariationContext.Current.PagesListName, resolvedPath.Substring(pagesPos + 6)); } } else if (value.StartsWith("~pages/", StringComparison.OrdinalIgnoreCase)) { string libraryPath = SPUrlUtility.CombineUrl(VariationContext.Current.TopWebServerRelativeUrl, VariationContext.Current.PagesListName); resolvedPath = String.Concat(libraryPath, value.Substring(6)); } else { resolvedPath = SPUtility.GetServerRelativeUrlFromPrefixedUrl(value); } if (uriKind == UriKind.Absolute) { return(SPUtility.GetFullUrl(SPContext.Current.Site, resolvedPath)); } return(resolvedPath); } return(value); }
protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel) { base.ProcessSPFieldXElement(fieldTemplate, fieldModel); var site = this.GetCurrentSite(); var typedFieldModel = fieldModel.WithAssertAndCast <LookupFieldDefinition>("model", value => value.RequireNotNull()); fieldTemplate.SetAttribute(BuiltInFieldAttributes.Mult, typedFieldModel.AllowMultipleValues.ToString().ToUpper()); if (typedFieldModel.LookupWebId.HasGuidValue()) { fieldTemplate.SetAttribute(BuiltInFieldAttributes.WebId, typedFieldModel.LookupWebId.Value.ToString("B")); } else if (!string.IsNullOrEmpty(typedFieldModel.LookupWebUrl)) { var targetWeb = GetTargetWeb(site, typedFieldModel); fieldTemplate.SetAttribute(BuiltInFieldAttributes.WebId, targetWeb.ID.ToString("B")); if (!targetWeb.IsRootWeb) { targetWeb.Dispose(); } } if (!string.IsNullOrEmpty(typedFieldModel.LookupList)) { fieldTemplate.SetAttribute(BuiltInFieldAttributes.List, typedFieldModel.LookupList); } else if (!string.IsNullOrEmpty(typedFieldModel.LookupListUrl)) { var targetWeb = GetTargetWeb(site, typedFieldModel); var list = targetWeb.GetList(SPUrlUtility.CombineUrl(targetWeb.ServerRelativeUrl, typedFieldModel.LookupListUrl)); fieldTemplate.SetAttribute(BuiltInFieldAttributes.List, list.ID.ToString()); if (!targetWeb.IsRootWeb) { targetWeb.Dispose(); } } else if (!string.IsNullOrEmpty(typedFieldModel.LookupListTitle)) { var targetWeb = GetTargetWeb(site, typedFieldModel); var list = targetWeb.Lists[typedFieldModel.LookupListTitle]; fieldTemplate.SetAttribute(BuiltInFieldAttributes.List, list.ID.ToString()); if (!targetWeb.IsRootWeb) { targetWeb.Dispose(); } } if (!string.IsNullOrEmpty(typedFieldModel.LookupField)) { fieldTemplate.SetAttribute(BuiltInFieldAttributes.ShowField, typedFieldModel.LookupField); } }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { var web = (SPWeb)properties.Feature.Parent; string listTitle = "Lists/" + Constants.Lists.NEWS; var list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, listTitle)); EventReceiverController.ProvisionListEventReceiver("EmailNotificationEventReceiver - ItemAdded", list, typeof(EmailNotificationEventReceiver), SPEventReceiverType.ItemAdded, SPEventReceiverSynchronization.Asynchronous, 20000); }
// Uncomment the method below to handle the event raised before a feature is deactivated. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { var web = (SPWeb)properties.Feature.Parent; string listTitle = "Lists/" + Constants.Lists.NEWS; var list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, listTitle)); EventReceiverController.DeleteListEventReceiver(list, typeof(EmailNotificationEventReceiver), SPEventReceiverType.ItemAdded); }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { using (SPWeb myWeb = (SPWeb)properties.Feature.Parent) { string masterUrl = SPUrlUtility.CombineUrl(myWeb.ServerRelativeUrl, "/_catalogs/masterpage/LappiaMasterPage.master"); myWeb.CustomMasterUrl = masterUrl; myWeb.Update(); } }
private static SPFile CopyInternal(SPWeb web, SPFile copyFile, string destinationFolderUrl, string destination) { web.AllowUnsafeUpdates = true; //move the source file to the new location copyFile.CopyTo(SPUrlUtility.CombineUrl(destination, copyFile.Name), false); web.AllowUnsafeUpdates = false; return(web.GetFile(web.Url + "/" + destinationFolderUrl + copyFile.Name)); }
// Удаляем файл private void deleteFile() { // Получаем элемент из библиотеки документов по UniqueID и удаляем его SPWeb web = SPContext.Current.Site.RootWeb; SPList list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, libraryName)); SPListItem spFileItem = list.GetItemByUniqueId(currentFile.UniqueID); spFileItem.Delete(); }
public static void MoveWebWithinSite(SPWeb sourceWeb, SPWeb parentWeb, string urlName) { // All we're doing is changing the URL name of the web. if (sourceWeb.IsRootWeb) { throw new SPCmdletException("Cannot change the URL name of the root of the Site Collection."); } sourceWeb.ServerRelativeUrl = SPUrlUtility.CombineUrl(parentWeb.ServerRelativeUrl, urlName); sourceWeb.Update(); }
public static IEnumerable <string> GetSiteUrls(SPWebApplication webApplication) { foreach (string sc in webApplication.Sites.Names) { yield return (string.IsNullOrEmpty(sc) ? SPUrlUtility.CombineUrl(webApplication.GetResponseUri(SPUrlZone.Default).AbsoluteUri, "/") : SPUrlUtility.CombineUrl(webApplication.GetResponseUri(SPUrlZone.Default).AbsoluteUri, sc)); } }
public static void Send_ObjsAndSkills_Rated_Email_to_HRCommittee(Emp intended_Emp, string Active_Rate_Goals_Year) { SPSecurity.RunWithElevatedPrivileges(delegate() { string html = File.ReadAllText(layoutsPath + "Send_ObjsAndSkills_Rated_Email_to_HRCommittee.html"); StringBuilder bodyText = new StringBuilder(html); #region If Arabic name not found, use English name string n = string.Empty; if (intended_Emp.Emp_ArabicName != null && intended_Emp.Emp_ArabicName != string.Empty) { n = intended_Emp.Emp_ArabicName; } else { n = intended_Emp.Emp_DisplayName; } #endregion If Arabic name not found, use English name bodyText.Replace("#EmpName#", n); bodyText.Replace("#Active_Rate_Goals_Year#", Active_Rate_Goals_Year); string encoded_name = HttpUtility.UrlEncode(intended_Emp.Emp_DisplayName); bodyText.Replace("#Link#", "<a href=" + SPContext.Current.Web.Url + "/Pages/RateObjectivesEmp.aspx?mode=hr&empid=" + encoded_name + " >" + n + "</a>"); #region Prepare Headers //get email of HRCommittee string HRCommittee_email = string.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite oSite = new SPSite(SPContext.Current.Web.Url); SPWeb spWeb = oSite.OpenWeb(); SPList spList = spWeb.GetList(SPUrlUtility.CombineUrl(spWeb.ServerRelativeUrl, "lists/" + "HRCommittee")); if (spList != null) { SPQuery qry = new SPQuery(); qry.ViewFieldsOnly = true; qry.ViewFields = @"<FieldRef Name='Title' />"; SPListItemCollection listItems = spList.GetItems(qry); HRCommittee_email = listItems[0]["Title"].ToString(); } }); StringDictionary headers = new StringDictionary(); headers.Add("to", HRCommittee_email); headers.Add("subject", " تم وضع تقييم الأهداف والكفاءات للموظف/الموظفة " + n); headers.Add("content-type", "text/html"); #endregion Prepare Headers SPUtility.SendEmail(SPContext.Current.Web, headers, bodyText.ToString()); }); }
protected SPSite GetExistingSite(SPWebApplication webApp, SiteDefinition definition) { var siteCollectionUrl = SPUrlUtility.CombineUrl(definition.PrefixName, definition.Url); if (webApp.Sites.Names.Contains(siteCollectionUrl)) { return(webApp.Sites[siteCollectionUrl]); } return(null); }