/// <summary> /// Sets the inital values of controls /// </summary> /// <param name="e">Event arguments</param> protected override void OnLoad(EventArgs e) { if (this.Page.Request["__EVENTTARGET"] == RibbonPostbackId) { _event = this.Page.Request["__EVENTARGUMENT"]; } if (_event == "Add") { Response.Redirect("/_layouts/Hemrika/ManageWebSiteModule.aspx?Source=/_layouts/Hemrika/ManageWebSiteModules.aspx", true); } // If AccessControl rules have not been created, they will need to be and therefore, AllowUnsafeUpdates must be set to true SPControl.GetContextWeb(Context).AllowUnsafeUpdates = true; foreach (IWebSiteControllerModule module in WebSiteControllerConfig.Modules) { TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.CssClass = "ms-descriptionText"; HyperLink link = new HyperLink(); link.NavigateUrl = "~/_layouts/Hemrika/ManageWebSiteModule.aspx?guid=" + module.Id.ToString() + "&Source=/_layouts/Hemrika/ManageWebSiteModules.aspx"; link.Text = module.GetType().FullName; cell.Controls.Add(link); row.Cells.Add(cell); this.entriesTable.Rows.Add(row); } SPControl.GetContextWeb(Context).AllowUnsafeUpdates = false; }
private void LoadResourceFileStrings() { try { string resources = GetResourceDirectory(); DirectoryInfo directoryInfo = new DirectoryInfo(this.Page.Server.MapPath(resources)); FileInfo[] languageFileInfoArray = directoryInfo.GetFiles(STR_LANGUAGE_FILTER); SPWeb web; for (int n = 0; n < languageFileInfoArray.Length; n++) { FileInfo fileInfo = languageFileInfoArray[n]; web = SPControl.GetContextWeb(this.Context); if (fileInfo.Name == (web.Language.ToString() + ".lng.xml")) { this._currentLanguage = web.Language.ToString(); } } if (this._currentLanguage == "") { this._currentLanguage = "1033"; } this._resourceFile = new XmlDocument(); XmlTextReader reader = new XmlTextReader(this.Page.Server.MapPath(resources + "/" + this._currentLanguage + ".lng.xml")); this._resourceFile.Load(reader); reader.Close(); } catch (Exception ex) { AddError(ex); } }
public static string GetPersonalPageUserName() { string userName; SPWeb web = SPControl.GetContextWeb(HttpContext.Current); SPServiceContext spServiceContext = SPServiceContext.GetContext(web.Site); UserProfileManager userProfileManager = new UserProfileManager(spServiceContext); string accountname = HttpContext.Current.Request.Params.Get("accountname"); if (accountname == null) { userName = web.CurrentUser.Name; } else { if (userProfileManager.UserExists(accountname)) { UserProfile userProfile = userProfileManager.GetUserProfile(accountname); userName = userProfile.DisplayName; } else { userName = ""; } } return(userName); }
internal static List <ListItem> GetAvailableValues(FilteredLookupField f, HttpContext ctx) { List <ListItem> _v = null; SPListItemCollection items = null; Guid fId = new Guid(f.LookupField); SPSite s = SPControl.GetContextSite(ctx); SPWeb lookupWeb = s.OpenWeb(f.LookupWebId); SPList lookupList = lookupWeb.Lists[new Guid(f.LookupList)]; try { if (f.QueryFilter != null) { items = lookupList.GetItems(f.QueryFilter); } } catch { } if (items == null) { items = lookupList.Items; } if ((items != null && items.Count > 0)) { _v = items .Cast <SPListItem>() .Where(e => e[fId] != null) .Select(e => new ListItem(( e.Fields[fId].GetFieldValueAsText(e[fId])), e.ID.ToString())) .ToList <ListItem>(); } return(_v); }
/// <summary>Initializes a new instance of <see cref="SlkCulture"/>.</summary> /// <param name="web">The web to localize.</param> public SlkCulture(SPWeb web) { Resources = new AppResourcesLocal(); Culture = System.Threading.Thread.CurrentThread.CurrentUICulture; if (web == null && HttpContext.Current != null) { web = SPControl.GetContextWeb(HttpContext.Current); } if (web != null) { #if SP2007 Culture = web.Locale; #else if (web.IsMultilingual) { // Just use the current UI culture as set above } else { // Not a multi-lingual site so return the web's locale Culture = web.Locale; } #endif } Resources.Culture = Culture; }
protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { FillContent(); FillSites(); SPWeb currentSite = SPControl.GetContextWeb(Context); if (!currentSite.DoesUserHavePermissions(SPBasePermissions.ManageSubwebs)) { newSubsite.Visible = false; } if (!currentSite.DoesUserHavePermissions(SPBasePermissions.ManageLists)) { newapp.Visible = false; } lblMessage.Text += "<br>Manage Web: " + currentSite.DoesUserHavePermissions(SPBasePermissions.ManageWeb).ToString(); lblMessage.Text += "<br>Manage Lists: " + currentSite.DoesUserHavePermissions(SPBasePermissions.ManageLists).ToString(); lblMessage.Text += "<br>Manage Subwebs: " + currentSite.DoesUserHavePermissions(SPBasePermissions.ManageSubwebs).ToString(); lblRecycleBinCount.Text = string.Format("({0})", currentSite.RecycleBin.Count.ToString()); } } catch (Exception ex) { lblMessage.Text += ex.ToString(); } }
private void InitializeFieldViews(SPField field, string webId, string listId) { SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(new Guid(webId)); SPList list = _web.Lists[new Guid(listId)]; foreach (SPView view in list.Views) { if ((view.Hidden || view.PersonalView) || !view.Type.Equals("HTML")) { continue; } ListItem item = new ListItem(view.Title, view.ID.ToString() + "|" + view.Url); string viewId = string.Empty; if (field != null) { CustomDropDownList f = field as CustomDropDownList; if (Convert.ToString(f.GetCustomProperty(CustomDropDownList.VIEW)) != string.Empty) { viewId = Convert.ToString(f.GetCustomProperty(CustomDropDownList.VIEW)); } } if (((view.ID.ToString() == viewId) || (view.ID.ToString() + "|" + view.Url == viewId))) { item.Selected = true; } ddlView.Items.Add(item); } ddlView.Items.Insert(0, new ListItem("", "")); ddlView.Visible = true; lbView.Visible = true; }
/// <summary> /// /// </summary> /// <param name="action">新的操作名称</param> /// <param name="typeFldName">类别字段名称</param> /// <param name="typeID">类别值</param> private int AddOperate(string action, int typeID) { CustomConcatenatedField f = (CustomConcatenatedField)base.Field; string lstID = f.LookupList; SPSite s = SPControl.GetContextSite(Context); int itemID = 0; SPWeb lookupWeb = SPControl.GetContextWeb(Context); int userID = lookupWeb.CurrentUser.ID; SPField typeFld = GetCascadedField; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(lookupWeb.Site.ID)) { using (SPWeb web = site.AllWebs[lookupWeb.ID]) { SPList lookupList = web.Lists[new Guid(lstID)]; SPListItem addItem = lookupList.Items.Add(); addItem["Title"] = action; addItem[typeFld.Title] = typeID; addItem[lookupList.Fields.GetFieldByInternalName("Flag").Title] = "11"; addItem["Author"] = userID; web.AllowUnsafeUpdates = true; addItem.Update(); web.AllowUnsafeUpdates = false; itemID = addItem.ID; } } }); return(itemID); }
/// <summary> /// 返回当前父级下的第一项的ID /// </summary> /// <param name="lstID"></param> /// <param name="fldInterlName"></param> /// <param name="fldCascaded"></param> /// <param name="cateID"></param> /// <returns></returns> private int GetListItemsOfFirstID(string lstID, string fldInterlName, string fldCascaded, int cateID) { SPSite s = SPControl.GetContextSite(Context); SPWeb lookupWeb = SPControl.GetContextWeb(Context); SPList lookupList = lookupWeb.Lists[new Guid(lstID)]; SPQuery qry = new SPQuery(); if (fldCascaded == "")//没有层次级别的分类,直接获取表中的所有数据 { qry.Query = @""; } else //通过父类ID进行层次级别的标识 { if (cateID > 0) { qry.Query = @"<Where><Eq><FieldRef Name='" + fldCascaded + "' LookupId='True' /><Value Type='Lookup'>" + cateID + "</Value></Eq></Where>"; } else { qry.Query = @"<Where><IsNull><FieldRef Name='" + fldCascaded + "' /></IsNull></Where>"; } } //查阅项列表 SPListItemCollection items = lookupList.GetItems(qry); int id = 0; if (items.Count > 0) { id = items[0].ID; } return(id); }
protected void LoadFolderNodes(SPFolder folder, TreeNode folderNode) { foreach (SPFolder childFolder in folder.SubFolders) { TreeNode childFolderNode = new TreeNode(childFolder.Name, childFolder.Name, FOLDER_IMG); childFolderNode.NavigateUrl = SPControl.GetContextWeb(this.Context).Site.MakeFullUrl(childFolder.Url); LoadFolderNodes(childFolder, childFolderNode); folderNode.ChildNodes.Add(childFolderNode); } foreach (SPFile file in folder.Files) { TreeNode fileNode; if (file.CustomizedPageStatus == SPCustomizedPageStatus.Uncustomized) { fileNode = new TreeNode(file.Name, file.Name, GHOSTED_FILE_IMG); } else { fileNode = new TreeNode(file.Name, file.Name, UNGHOSTED_FILE_IMG); } fileNode.NavigateUrl = SPControl.GetContextWeb(this.Context).Site.MakeFullUrl(file.Url); folderNode.ChildNodes.Add(fileNode); } }
public override PickerEntity ValidateEntity(PickerEntity needsValidation) { PickerEntity entity = needsValidation; if (!string.IsNullOrEmpty(needsValidation.DisplayText)) { using (SPWeb web = SPControl.GetContextWeb(Context)) { FieldLookupWithPickerPropertyBag propertyBag = new FieldLookupWithPickerPropertyBag(this.CustomProperty); SPList list = web.Lists[propertyBag.ListId]; SPQuery queryById = new SPQuery(); queryById.Query = string.Format("<Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">{0}</Value></Eq></Where>", needsValidation.Key); SPListItemCollection items = list.GetItems(queryById); if (items.Count > 0) { entity = this.GetEntity(items[0]); } else { SPQuery queryByTitle = new SPQuery(); queryByTitle.Query = string.Format("<Where><Eq><FieldRef Name=\"{0}\"/><Value Type=\"Text\">{1}</Value></Eq></Where>", propertyBag.FieldId, needsValidation.DisplayText); items = list.GetItems(queryByTitle); if (items.Count > 0) { entity = this.GetEntity(items[0]); } } } } return(entity); }
protected void CopyItem(object sender, EventArgs e) { int itemid = Convert.ToInt32(Request.QueryString["ItemId"]); Guid listid = new Guid(Request.QueryString["ListId"]); SPWeb sourceweb = SPControl.GetContextWeb(HttpContext.Current); SPList sourcelist = sourceweb.Lists[listid]; SPListItem sourceitem = sourcelist.GetItemById(itemid); lblListItem.Text = sourceitem.Name; TreeNodeContext ctx = new TreeNodeContext(tvSite.SelectedValue); SPSite destcol = new SPSite(ctx.SiteCollection); SPWeb destweb = destcol.AllWebs[ctx.WebID]; if (ctx.IsList) { SPList destlist = destweb.Lists[ctx.ListID]; SPListItem destitem = destlist.Items.Add(); SPFolder folder = destlist.RootFolder; try { folder.Files.Add(sourceitem.Name, sourceitem.File.OpenBinary()); } catch (Exception ex) { lblStatus.Text = string.Format("Error uploading File {0}", sourceitem.Name); } lblStatus.Text = string.Format("{0} copied successfully to {1}", sourceitem.Name, destlist.Title); } }
protected override void Render(HtmlTextWriter writer) { HttpContext context = HttpContext.Current; SPWeb site = SPControl.GetContextWeb(context); SPUser user = site.CurrentUser; string output = string.Format("Hi {0} - Welcome to the site {1}", user.Name, site.Name); writer.Write(output); }
internal static WebPart GetSourceWebPart(string url, string webPartTitle, string webPartId, out string zone) { using (SPSite site = new SPSite(url)) using (SPWeb web = site.OpenWeb()) // The url contains a filename so AllWebs[] will not work unless we want to try and parse which we don't { bool cleanupContext = false; try { if (HttpContext.Current == null) { cleanupContext = true; HttpRequest httpRequest = new HttpRequest("", web.Url, ""); HttpContext.Current = new HttpContext(httpRequest, new HttpResponse(new StringWriter())); SPControl.SetContextWeb(HttpContext.Current, web); } SPLimitedWebPartManager manager = null; try { WebPart webPart = null; if (!string.IsNullOrEmpty(webPartTitle)) { webPart = Utilities.GetWebPartByTitle(web, url, webPartTitle, out manager); } else if (!string.IsNullOrEmpty(webPartId)) { webPart = Utilities.GetWebPartById(web, url, webPartId, out manager); } if (manager != null) { zone = manager.GetZoneID(webPart); } else { zone = null; } return(webPart); } finally { if (manager != null) { manager.Web.Dispose(); manager.Dispose(); } } } finally { if (HttpContext.Current != null && cleanupContext) { HttpContext.Current = null; } } } }
private void SetTargetWeb() { listTargetWeb.Items.Clear(); List <ListItem> str = new List <ListItem>(); //using (SPSite _site = SPControl.GetContextSite(this.Context)) { SPSite _site = SPControl.GetContextSite(this.Context); SPWebCollection _webCollection = _site.AllWebs; string contextWebId = SPControl.GetContextWeb(this.Context).ID.ToString(); foreach (SPWeb web in _webCollection) { try { if (web.DoesUserHavePermissions( SPBasePermissions.ViewPages | SPBasePermissions.OpenItems | SPBasePermissions.ViewListItems)) { str.Add(new ListItem(web.Title, web.ID.ToString())); } } catch (Exception ex) { LoggingService.WriteTrace(Area.EPMLiveCore, Categories.EPMLiveCore.IntegrationCore, TraceSeverity.Medium, ex.ToString()); } finally { if (web != null) { web.Dispose(); } } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetWeb.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetWebId)) { bitem = listTargetWeb.Items.FindByValue(TargetWebId); } else { bitem = listTargetWeb.Items.FindByValue(contextWebId); } if (bitem != null) { listTargetWeb.SelectedIndex = listTargetWeb.Items.IndexOf(bitem); } else { listTargetWeb.SelectedIndex = 0; } SetTargetList(listTargetWeb.SelectedItem.Value, true); } }
/// <summary> /// Overridden method CreateChildControls from the Webpart class /// </summary> protected override void CreateChildControls() { this.currentSite = SPControl.GetContextSite(Context); this.currentWeb = this.currentSite.OpenWeb(WebName); try { this.currentList = this.currentWeb.Lists[ListName]; this.listRootFolder = this.currentWeb.Lists[ListName].RootFolder.ToString(); } }
private void InitializeApplication() { UrlQuery query = new UrlQuery(this.Page.Request.Url.ToString()); ForumApplication.Instance.BasePath = SPEncode.UrlEncodeAsUrl(query.Url); ForumApplication.Instance.Title = this.Name; ForumApplication.Instance.ForumCache = this.Page.Cache; ForumApplication.Instance.ClassResourcePath = this.ClassResourcePath; ForumApplication.Instance.SpUser = SPControl.GetContextWeb(Context).CurrentUser; ForumApplication.Instance.AppPoolUser = SPControl.GetContextSite(Context).OpenWeb().CurrentUser; ForumApplication.Instance.SpWeb = SPControl.GetContextSite(Context).OpenWeb(); }
/// <summary> /// This is the standard method for adding controls to a web part. /// </summary> protected override void CreateChildControls() { ddlGroup = new DropDownList(); SPWeb web = SPControl.GetContextWeb(Context); SPGroupCollection groups = web.SiteGroups; for (int idx = 0; idx < groups.Count; idx++) { ddlGroup.Items.Add(groups[idx].Name); } this.Controls.Add(ddlGroup); }
protected override void CreateChildControls() { try { if (!this.Page.IsPostBack) { string test = "Test"; } SPWeb topWeb = SPControl.GetContextWeb(this.Context).Site.RootWeb; ds = new SPHierarchyDataSourceControl(); ds.Web = topWeb; ds.RootWebId = topWeb.Site.RootWeb.ID.ToString(); ds.RootContextObject = null; //ds.RootContextObject = "Web"; ds.ID = "TreeViewDataSource"; ds.IncludeDiscussionFolders = true; ds.ShowListChildren = true; ds.ShowDocLibChildren = true; ds.ShowFolderChildren = true; ds.DataBind(); Controls.Add(ds); tvw = new SPTreeView(); tvw.ID = "WebTreeView"; tvw.ShowLines = false; tvw.DataSourceID = "TreeViewDataSource"; tvw.ExpandDepth = 1; tvw.EnableClientScript = true; tvw.EnableViewState = true; tvw.NodeStyle.CssClass = "ms-navitem"; tvw.NodeStyle.HorizontalPadding = 2; tvw.SelectedNodeStyle.CssClass = "ms-tvselected"; tvw.SkipLinkText = ""; tvw.NodeIndent = 12; tvw.ExpandImageUrl = "/_layouts/images/tvplus.gif"; tvw.CollapseImageUrl = "/_layouts/images/tvminus.gif"; tvw.NoExpandImageUrl = "/_layouts/images/tvblank.gif"; tvw.TreeNodeExpanded += Node_Expand; Controls.Add(tvw); //tvw.DataBind(); base.CreateChildControls(); } catch (Exception e) { string exp = "e.ToString"; } }
private void SetTargetList(string selectedWebId, bool setTargetColumn) { listTargetList.Items.Clear(); if (!string.IsNullOrEmpty(selectedWebId)) { //using (SPSite _site = SPControl.GetContextSite(this.Context)) { // using (SPWeb _web = _site.OpenWeb(new Guid(selectedWebId))) { SPSite _site = SPControl.GetContextSite(this.Context); using (SPWeb _web = _site.OpenWeb(new Guid(selectedWebId))) { List <ListItem> str = new List <ListItem>(); SPListCollection _listCollection = _web.Lists; foreach (SPList list in _listCollection) { if (!list.Hidden) { str.Add(new ListItem(list.Title, list.ID.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetList.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetListId)) { bitem = listTargetList.Items.FindByValue(TargetListId); } if (bitem != null) { listTargetList.SelectedIndex = listTargetList.Items.IndexOf(bitem); } else { listTargetList.SelectedIndex = 0; } if (setTargetColumn) { SetTargetColumn(selectedWebId, listTargetList.SelectedItem.Value); } SetTargetListView(selectedWebId, listTargetList.SelectedItem.Value); } } } }
//</Snippet3> //<Snippet4> protected void Button1_Click(object sender, EventArgs e) { SPCalendarItemCollection items = new SPCalendarItemCollection(); SPWeb thisWeb = SPControl.GetContextWeb(Context); foreach (ListItem item in CheckBoxList1.Items) { if (item.Selected == true) { SPList calendarList = thisWeb.Lists[item.Text]; DateTime dtStart = DateTime.Now.AddDays(-7); DateTime dtEnd = dtStart.AddMonths(1).AddDays(7); SPQuery query = new SPQuery(); query.Query = String.Format( "<Query>" + "<Where><And>" + "<Geq><FieldRef Name=\"{0}\" />" + "<Value Type=\"DateTime\">{1}</Value></Geq>" + "<Leq><FieldRef Name=\"{0}\" />" + "<Value Type=\"DateTime\">{2}</Value></Leq>" + "</And></Where><OrderBy><FieldRef Name=\"{0}\" /></OrderBy>" + "</Query>", "Start Time", dtStart.ToShortDateString(), dtEnd.ToShortDateString()); foreach (SPListItem listItem in calendarList.GetItems(query)) { SPCalendarItem calItem = new SPCalendarItem(); calItem.ItemID = listItem["ID"].ToString(); calItem.Title = listItem["Title"].ToString(); calItem.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian); calItem.StartDate = (DateTime)listItem["Start Time"]; calItem.ItemID = listItem.ID.ToString(); calItem.WorkSpaceLink = String.Format( "/Lists/{0}/DispForm.aspx", calendarList.Title); calItem.DisplayFormUrl = String.Format( "/Lists/{0}/DispForm.aspx", calendarList.Title); calItem.EndDate = (DateTime)listItem["End Time"]; calItem.Description = listItem["Description"].ToString(); if (listItem["Location"] != null) { calItem.Location = listItem["Location"].ToString(); } items.Add(calItem); } MonthlyCalendarView1.DataSource = items; } } }
public bool Insertar(PasantiasPreProfesionales item, out int?id) { bool result = false; int? auxId = 0; string strUrl = Properties.UdlaListDefinitions.Default.Url_Sitio; try { if (SPContext.Current != null) { HttpContext.Current = null; } SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite oSite = new SPSite(strUrl)) { using (SPWeb oWeb = oSite.OpenWeb()) { HttpRequest httpRequest = new HttpRequest("", oWeb.Url, ""); HttpContext.Current = new HttpContext(httpRequest, new HttpResponse(new System.IO.StringWriter())); SPControl.SetContextWeb(HttpContext.Current, oWeb); using (UdlaEntityDataContext context = new UdlaEntityDataContext(oWeb.Url)) { EntityList <ListaPasantiasElemento> pasantias = context.GetList <ListaPasantiasElemento>(Properties.UdlaListDefinitions.Default.Lista_Pasantias); var itemBase = MappeoMoss(item); pasantias.InsertOnSubmit(itemBase); context.SubmitChanges(); itemBase.Accion = string.Format(itemBase.Accion, itemBase.Identificador); itemBase.Título = string.Format(itemBase.Título, itemBase.Identificador); context.SubmitChanges(); auxId = itemBase.Identificador; result = true; } } } } ); } catch (Exception ex) { auxId = 0; Logger.ExLogger(ex); throw ex; } id = auxId; return(result); }
private void SetTargetListView(string webId, string selectedListId) { listTargetListView.Items.Clear(); // clear list, first and foremost if (!string.IsNullOrEmpty(webId) && !string.IsNullOrEmpty(selectedListId)) { //using (SPSite _site = SPControl.GetContextSite(this.Context)) { // using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPSite _site = SPControl.GetContextSite(this.Context); using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPList list = _web.Lists[new Guid(selectedListId)]; SPViewCollection views = list.Views; List <ListItem> str = new List <ListItem>(); foreach (SPView v in views) { // use only views that are both visible and shared if (!v.Hidden && !v.PersonalView) { str.Add(new ListItem( string.Format(CultureInfo.InvariantCulture, "{0}", v.Title), v.ID.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetListView.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetListViewId)) { bitem = listTargetListView.Items.FindByValue(TargetListViewId); } if (bitem != null) { listTargetListView.SelectedIndex = listTargetListView.Items.IndexOf(bitem); } else { listTargetListView.SelectedIndex = 0; } } } } }
protected void BindRedmineData() { string userName = WebPartsHelper.GetPersonalPageUserName(); SPWeb web = SPControl.GetContextWeb(HttpContext.Current); AppSettingsSection appSettings = WebPartsHelper.GetWebAppSettings(web); RedmineData.InitParams(appSettings); List <RedmineIssue> issuesByUser = RedmineData.GetUserIssuesAndSetCache(userName); Array issuesArrayForGridView = RedmineData.ConvertRedmineIssuesToArrayForGridView(issuesByUser); RedmineGridView.PagerTemplate = null; RedmineGridView.DataSource = issuesArrayForGridView; RedmineGridView.DataBind(); }
public bool Insertar(Actividades item, out int?id) { bool result = false; int? auxId = 0; string strUrl = Properties.UdlaListDefinitions.Default.Url_Sitio; try { if (SPContext.Current != null) { HttpContext.Current = null; } SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite oSite = new SPSite(strUrl)) { using (SPWeb oWeb = oSite.OpenWeb()) { HttpRequest httpRequest = new HttpRequest("", oWeb.Url, ""); HttpContext.Current = new HttpContext(httpRequest, new HttpResponse(new System.IO.StringWriter())); SPControl.SetContextWeb(HttpContext.Current, oWeb); using (UdlaEntityDataContext context = new UdlaEntityDataContext(oWeb.Url)) { EntityList <ListaDeActividadesPorEstudianteElemento> actividades = context.GetList <ListaDeActividadesPorEstudianteElemento>(Properties.UdlaListDefinitions.Default.Lista_Actividades); var itemBase = MappeoMoss(item); itemBase.Identificador = null; itemBase.IdPasantia = context.ListaPasantias.Where(x => x.Identificador == item.idPasantia).Take(1).ToList().First(); actividades.InsertOnSubmit(itemBase); context.SubmitChanges(); auxId = itemBase.Identificador; result = true; } } } } ); } catch (Exception ex) { auxId = 0; Logger.ExLogger(ex); throw ex; } id = auxId; return(result); }
private void SetTargetWeb() { listTargetWeb.Items.Clear(); List <ListItem> str = new List <ListItem>(); SPSite _site = SPControl.GetContextSite(this.Context); SPWebCollection _webCollection = _site.AllWebs; string contextWebId = SPControl.GetContextWeb(this.Context).ID.ToString(); foreach (SPWeb web in _webCollection) { if (web.DoesUserHavePermissions( SPBasePermissions.ViewPages | SPBasePermissions.OpenItems | SPBasePermissions.ViewListItems)) { str.Add(new ListItem(web.Title, web.ID.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetWeb.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetWebId)) { bitem = listTargetWeb.Items.FindByValue(TargetWebId); } else { bitem = listTargetWeb.Items.FindByValue(contextWebId); } if (bitem != null) { listTargetWeb.SelectedIndex = listTargetWeb.Items.IndexOf(bitem); } else { listTargetWeb.SelectedIndex = 0; } SetTargetList(listTargetWeb.SelectedItem.Value, true); } }
private void SetTargetColumn(string webId, string selectedListId) { listTargetColumn.Items.Clear(); if (!string.IsNullOrEmpty(webId) && !string.IsNullOrEmpty(selectedListId)) { //using (SPSite _site = SPControl.GetContextSite(this.Context)) { // using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPSite _site = SPControl.GetContextSite(this.Context); using (SPWeb _web = _site.OpenWeb(new Guid(webId))) { SPList list = _web.Lists[new Guid(selectedListId)]; SPFieldCollection fields = list.Fields; List <ListItem> str = new List <ListItem>(); foreach (SPField f in fields) { if (CanFieldBeDisplayed(f)) { str.Add(new ListItem( string.Format(CultureInfo.InvariantCulture, "{0}", f.Title), f.Id.ToString())); } } if (str.Count > 0) { str.Sort(delegate(ListItem item1, ListItem item2) { return(item1.Text.CompareTo(item2.Text)); }); listTargetColumn.Items.AddRange(str.ToArray()); ListItem bitem = null; if (!string.IsNullOrEmpty(TargetColumnId)) { bitem = listTargetColumn.Items.FindByValue(TargetColumnId); } if (bitem != null) { listTargetColumn.SelectedIndex = listTargetColumn.Items.IndexOf(bitem); } else { listTargetColumn.SelectedIndex = 0; } } } } }
protected override void OnLoad(EventArgs e) { // ensure the user is an administrator, then execute the remaining code within a // LearningStorePrivilegedScope (which grants full access to database views) if (!SPFarm.Local.CurrentUserIsAdministrator()) { throw new UnauthorizedAccessException( "Access is denied. Only adminstrators can access this page."); } using (new LearningStorePrivilegedScope()) { // skip the code below during postback since <OriginalInstructor> will have been // populated from view state already if (IsPostBack) { return; } // populate the <OriginalInstructor> drop-down list with the names and SLK user // identifiers of all users who are instructors on any assignments in the current // SharePoint site collection using (SPWeb spWeb = SPControl.GetContextWeb(HttpContext.Current)) { SlkStore slkStore = SlkStore.GetStore(spWeb); LearningStoreJob job = slkStore.LearningStore.CreateJob(); LearningStoreQuery query = slkStore.LearningStore.CreateQuery( "AllAssignmentInstructors"); query.SetParameter("SPSiteGuid", spWeb.Site.ID); query.AddColumn("InstructorName"); query.AddColumn("InstructorId"); query.AddSort("InstructorName", LearningStoreSortDirection.Ascending); job.PerformQuery(query); DataRowCollection rows = job.Execute <DataTable>().Rows; OriginalInstructor.Items.Add(String.Empty); foreach (DataRow row in rows) { ListItem listItem = new ListItem(); listItem.Text = (string)row["InstructorName"]; UserItemIdentifier originalInstructorId = new UserItemIdentifier((LearningStoreItemIdentifier)row["InstructorId"]); listItem.Value = originalInstructorId.GetKey().ToString( CultureInfo.InvariantCulture); OriginalInstructor.Items.Add(listItem); } } } }
/// <summary> /// Relative url for zoom builder /// </summary> /// <returns>The relative Url</returns> private static string ZoomBuilderRelativeUrl() { HttpContext current = HttpContext.Current; SPWeb web = SPControl.GetContextWeb(current); string relative = web.ServerRelativeUrl; if (relative == "/") { relative = "/_layouts/zoombldr.aspx"; } else { relative += "/_layouts/zoombldr.aspx"; } return(SPEncode.UrlEncodeAsUrl(relative)); }
void IFieldEditor.OnSaveChange(SPField field, bool isNewField) { this.EnsureChildControls(); if (field != null) { CustomConcatenatedField _f = field as CustomConcatenatedField; SPSite _site = SPControl.GetContextSite(this.Context); SPWeb _web = _site.OpenWeb(); _f.LookupWebId = _web.ID; _f.LookupList = ddlListName.SelectedValue; _f.LookupField = ddlFieldName.SelectedValue; _f.SPLookupList = ddlListName.SelectedValue; _f.SPLookupField = ddlFieldName.SelectedValue; _f.SPLookupWidth = txtWidth.Text; } }