protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string encodedListId = SPEncode.UrlEncode(this.ListGuid.ToString("B").ToUpper()); linkNewView.NavigateUrl += "List=" + encodedListId; linkNewViewCalendar.NavigateUrl += "List=" + encodedListId; } }
protected override void CreateChildControls() { Controls.Clear(); SPWeb web = SPContext.Current.Web; newItemPanel = new Panel() { ID = "panelNewItem" }; string navigateUrl = "javascript:void(0);"; string webUrl = SPContext.Current.Web.ServerRelativeUrl.TrimEnd('/'); string listId = SPEncode.UrlEncode(this.List.Id.ToString("B").ToUpper()); if (!this.IsMultiContentTypeList) { navigateUrl = string.Format("javascript:SP.UI.ModalDialog.ShowPopupDialog('{0}')", BuidUri(string.Format(URL_FORMAT, webUrl, this.List.DefaultContent.NewItemUrl.TrimStart('/'), listId), this.UrlParamsFromParent)); } HyperLink addNewLink = new HyperLink { ID = "linkAddNewItem", ToolTip = "new item", CssClass = "ms-heroCommandLink " + this.List.Id.ToString("N"), NavigateUrl = navigateUrl }; Label addNewImgLabel = new Label() { CssClass = "ms-list-addnew-imgSpan20" }; Image addNewImg = new Image { ImageUrl = "/_layouts/15/images/spcommon.png?rev=23", CssClass = "ms-list-addnew-img20" }; Label addNewLabel = new Label() { Text = "new item" }; addNewImgLabel.Controls.Add(addNewImg); addNewLink.Controls.Add(addNewImgLabel); addNewLink.Controls.Add(addNewLabel); // add extra hidden SELECT control to access all list Content types from Ribbon Button DropDownList ctList = new DropDownList { ID = "listOfContentTypes", CssClass = "ct-for-" + this.List.Id.ToString("N").ToUpper() }; ctList.Style.Add("display", "none"); ctList.Items.AddRange(this.VisibleContentTypes.Select(item => new ListItem(item.Name, BuidUri(string.Format(URL_FORMAT, webUrl, item.NewItemUrl.TrimStart('/'), listId), UrlParamsFromParent))).ToArray()); newItemPanel.Controls.Add(addNewLink); newItemPanel.Controls.Add(ctList); this.Controls.Add(newItemPanel); }
private string GetMenuJsScript() { var webUrl = SPContext.Current.Web.ServerRelativeUrl.TrimEnd('/'); var listId = SPEncode.UrlEncode(this.List.Id.ToString("B").ToUpper()); const string menuItemFormat = "\"{0}\": {{name: \"{0}\", callback: function(key, opt){{ SP.UI.ModalDialog.ShowPopupDialog('{1}'); }}}}"; var menuItems = VisibleContentTypes.Select(item => string.Format(menuItemFormat, item.Name, BuidUri(string.Format(URL_FORMAT, webUrl, item.NewItemUrl.TrimStart('/'), listId), UrlParamsFromParent))).ToList(); return(string.Format("{{{0}}}", string.Join(",", menuItems))); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { if (this.List == null) { throw new Exception("List not found"); } // init List name lblListName.Text = this.List.Name; // Add fields var allFields = this.List.ListMetadataContentTypes.SelectMany(ct => ct.ListMetadataFieldContentTypes.Select(ctf => new { ContentType = ct.Name, FieldId = ctf.ListMetadataFieldId, Field = ctf.ListMetadataField })); ColumnsRepeater.DataSource = allFields.GroupBy(g => g.FieldId).Select(g => new { Id = g.Key, FieldName = g.First().Field.FieldName, FieldType = g.First().Field.FieldType, UsedIn = string.Join(", ", g.Select(x => x.ContentType)) }).OrderBy(f => f.FieldName); ColumnsRepeater.DataBind(); // Add Content Types ContTypesRepeater.DataSource = this.List.ListMetadataContentTypes.OrderBy(ct => ct.IsDefault); ContTypesRepeater.DataBind(); // Add Views ViewsRepeater.DataSource = this.ListViews.OrderBy(f => f.Name); ViewsRepeater.DataBind(); // add 'List' url param to links string encodedListId = SPEncode.UrlEncode(this.ListGuid.ToString("B").ToUpper()); linkNewField.NavigateUrl += "?List=" + encodedListId; linkNewView.NavigateUrl += "?List=" + encodedListId; linkNewContentType.NavigateUrl += "?List=" + encodedListId; linkListPermissions.NavigateUrl += "?ListId=" + encodedListId; } catch (Exception ex) { panelErrror.Controls.Add(new Microsoft.SharePoint.Mobile.Controls.Label() { Text = ex.Message }); } } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { SPWeb web = __Context.Web; SPList list = web.Lists[Microsoft.SharePoint.WorkflowActions.Helper.GetListGuid(__Context, ListId)]; SPFolder folder = list.RootFolder; SPFile file = folder.Files.Add(FileName, Encoding.UTF8.GetBytes(Xml), Overwrite); FileItemId = new SPItemKey(file.Item.ID); FileUrl = SPEncode.UrlEncode(web.Url + "/" + file.Url); return(ActivityExecutionStatus.Closed); }
static void Main(string[] args) { using (SPSite site = new SPSite("http://testsp2007")) { using (SPWeb web = site.OpenWeb("/ik")) { SPList list = web.GetList(web.Url + "/Lists/Departmanlar"); SPQuery query = new SPQuery(); query.RowLimit = 5000; string sp2016url = "http://testsp2016/ik"; string saatbody = string.Empty, saatoutlookbody = string.Empty; string listurl = "_api/web/Lists?$expand=ListItemAllFields&$filter=Title eq 'Departmanlar'"; string encodedlisturl = SPEncode.UrlEncode(listurl); string listguid = RestHelper.GetIdOfList(sp2016url + SPEncode.UrlDecodeAsUrl(encodedlisturl), sp2016url + "_api/contextinfo"); SPListItemCollection items = list.GetItems(query); foreach (SPListItem item in items) { try { if (item != null) { var sirket = Helper.Get_LookUp("Sirket", item, web, sp2016url, "SirketId"); var title = Helper.Get_String("Title", item, web, sp2016url, "Title"); var mudur = Helper.Get_Group("Mudur", item, web, sp2016url, "MudurId"); RestHelper.RestYap("{'__metadata': {'type': 'SP.Data.DepartmanlarListItem'}," + sirket + "," + title + "," + mudur + " }", sp2016url + "_api/contextinfo", listguid + "/items", listguid, false, false, false, false); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { if (this.ContentType == null) { throw new Exception("Content Type not found"); } // init Content Type name lblContentTypeName.Text = this.ContentType.Name; // Add fields ColumnsRepeater.DataSource = this.ContentType.ListMetadataFieldContentTypes.OrderBy(f => f.ItemPosition).Select(f => f.ListMetadataField); ColumnsRepeater.DataBind(); // add 'ContentType' url param to links string encodedContentTypeId = SPEncode.UrlEncode(this.ContentTypeId.ToString()); linkFormSettings.NavigateUrl += "?ContentType=" + encodedContentTypeId; linkNewField.NavigateUrl += "?ContentType=" + encodedContentTypeId; linkFieldsOrdering.NavigateUrl += "?ContentType=" + encodedContentTypeId; linkAddField.NavigateUrl += "?ContentType=" + encodedContentTypeId; // add 'List' url param to links string encodedListId = SPEncode.UrlEncode(this.ContentType.ListMetadataId.ToString("B").ToUpper()); linkNewField.NavigateUrl += "&List=" + encodedListId; btnDelete.Visible = !this.ContentType.IsDefault; } catch (Exception ex) { panelErrror.Controls.Add(new Microsoft.SharePoint.Mobile.Controls.Label() { Text = ex.Message }); } } }
public static string DisplayFormUrl(this SPListItem item) { SPList list = item.ParentList; SPWeb web = list.ParentWeb; string webUrl = web.Url; string dispUrl = item.ContentType.DisplayFormUrl; if (dispUrl == "") { dispUrl = list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url; } bool isLayouts = dispUrl.StartsWith("_layouts/", StringComparison.CurrentCultureIgnoreCase); dispUrl = String.Format("{0}/{1}?ID={2}", webUrl, dispUrl, item.ID); if (isLayouts) { dispUrl = String.Format("{0}&List={1}", dispUrl, SPEncode.UrlEncode(list.ID + "")); } return(dispUrl); }
public static void ProvisionWebpart(SPWeb web, WebpartPageDefinitionCollection collection) { foreach (var item in collection) { try { string pageUrl = item.PageUrl; if (!string.IsNullOrEmpty(item.RootPath) && !string.IsNullOrEmpty(item.FileName)) { if (item.RootPath.EndsWith(".aspx")) { item.PageUrl = item.RootPath; pageUrl = item.RootPath; } else { pageUrl = string.Format("{0}/{1}", item.RootPath.TrimEnd('/'), SPEncode.UrlEncode(item.FileName.TrimStart('/'))); item.PageUrl = pageUrl; } } if (!IsAbsoluteUrl(pageUrl)) { pageUrl = string.Format("{0}/{1}", web.Url.TrimEnd('/'), pageUrl.TrimStart('/')); } web.EnsureWebpartPage(item.PageUrl, item.Title, item.Overwrite, item.UseFormFolder); using (SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager( pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)) { foreach (var wp in item.Webparts) { try { using (var concerateWP = wp.CreateWebPart(web, webPartManager)) { if (concerateWP == null) { continue; } try { if (!wp.AllowDuplicate && webPartManager.WebParts.Cast <System.Web.UI.WebControls.WebParts.WebPart>().Any(p => p.Title == concerateWP.Title)) { continue; } } catch (Exception) { //throw; } webPartManager.AddWebPart(concerateWP, wp.ZoneId, wp.Index == 0 ?webPartManager.WebParts.Count + 1: wp.Index); CreateDefaultWebPart(web, webPartManager, wp, concerateWP); } } catch (Exception ex) { } } } } catch (Exception ex) { } } }
public SPCalendarItemCollection SelectDataForCalendar(short calendarType, Tuple <DateTime, DateTime> calendarPeriod, string calendarScope, out object rostersForColoring) { var query = new QueryParams(); var listFields = this.m_view.ListMetadata.ListMetadataFields; var startDateFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.START_DATE); var endDateFld = listFields.FirstOrDefault(item => item.InternalName == FieldNames.END_DATE); // set filter according period displayed by Calendar query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(startDateFld, CompareType.LessOrEqual, ConcateOperator.And, calendarPeriod.Item2, null)); query.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(endDateFld, CompareType.MoreOrEqual, ConcateOperator.And, calendarPeriod.Item1, null)); // add filter if (this.m_GridFilterExpression != null && this.m_GridFilterExpression.WhereCriteria.Any()) { query.WhereCriteria.AddRange(this.m_GridFilterExpression.WhereCriteria); } // extract Roster data RosterDataService _dataSrv = new RosterDataService(); //List<RosterEvent> rosters = (this.m_view.ListMetadataId == Roster.Common.TableIDs.TIMESHEET_ROSTERS && this.displayPrepopulatedRosters) ? // _dataSrv.ViewTimesheetEvents(this.m_view.Id, query, calendarPeriod) : _dataSrv.ViewRosterEvents(this.m_view.Id, query); List <RosterEvent> rosters = _dataSrv.ViewRosterEvents(this.m_view.Id, query); // expant recurrent events var tZone = SPContext.Current.Web.RegionalSettings.TimeZone; List <ExpandedRosterEvent> expandedEvents = RecurrenceItemExpander.Expand(rosters, null, calendarPeriod.Item1, calendarPeriod.Item2, FieldNames.START_DATE, FieldNames.END_DATE, tZone).ToList(); // send Object to output for coloring if (!this.m_view.GetDerializedDynamicColourSettings().IsEmpty) { if (this.dynColoring_OriginalRosterId != Guid.Empty && !rosters.Any(r => r.Id == this.dynColoring_OriginalRosterId)) { List <RosterEvent> rosters_dynColor = rosters; RosterEvent origRoster = _dataSrv.GetRosterEvent(this.dynColoring_OriginalRosterId); // !! don't return all properties // get events around Orig.Roster var queryDyn = new QueryParams(); queryDyn.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(startDateFld, CompareType.LessOrEqual, ConcateOperator.And, origRoster.GetEndDate(), null)); queryDyn.WhereCriteria.Add(new Tuple <ListMetadataField, CompareType, ConcateOperator, object, string>(endDateFld, CompareType.MoreOrEqual, ConcateOperator.And, origRoster.GetStartDate(), null)); rosters_dynColor.AddRange(_dataSrv.ViewRosterEvents(this.m_view.Id, queryDyn)); rosters_dynColor = rosters_dynColor.GroupBy(r => r.Id).Select(g => g.First()).ToList(); // remove duplicates rostersForColoring = RecurrenceItemExpander.Expand(rosters_dynColor, null, calendarPeriod.Item1, calendarPeriod.Item2, FieldNames.START_DATE, FieldNames.END_DATE, tZone); // for dynamic coloring // add original Roster (only for Dynamic colour-coding) expandedEvents.Add(new ExpandedRosterEvent(rosters_dynColor.First(r => r.Id == this.dynColoring_OriginalRosterId), true, tZone)); } else { rostersForColoring = expandedEvents; // for dynamic coloring } } else { rostersForColoring = rosters; // for static coloring } // get default DispForm url and default EventTypeId for rosters string defaultDispFormUrl = string.Format("{0}/{1}&ListId={2}", SPContext.Current.Web.ServerRelativeUrl.TrimEnd('/'), this.m_view.ListMetadata.DispItemUrl.TrimStart('/'), SPEncode.UrlEncode(this.m_view.ListMetadataId.ToString("B").ToUpper())); var matchEventType = Regex.Match(defaultDispFormUrl, @"EventType=(?<eType>\d+)"); int defaultEventType = matchEventType.Success ? matchEventType.Groups["eType"].Value.ToInt() : -1; string eventTitleFieldName = this.m_view.GetEventTitleFieldName(calendarScope); string eventLocationFieldName = this.m_view.GetEventLocationFieldName(calendarScope); // init some variables for Working Rosters which are displayed on TIMESHEET view string workingRoster_DispFormUrl = string.Empty; string workingRosterEventTitleFieldName = string.Empty; string workingRosterEventLocationFieldName = string.Empty; if (this.m_view.ListMetadataId == Roster.Common.TableIDs.TIMESHEET_ROSTERS) { var workingRosterList = new RosterConfigService().GetList(Roster.Common.TableIDs.WORKING_ROSTERS); workingRoster_DispFormUrl = string.Format("{0}/{1}&ListId={2}", SPContext.Current.Web.ServerRelativeUrl.TrimEnd('/'), workingRosterList.DispItemUrl.TrimStart('/'), SPEncode.UrlEncode(workingRosterList.Id.ToString("B").ToUpper())); var workingRosterView = workingRosterList.ViewMetadatas.FirstOrDefault(x => x.Name == ViewNames.WORKING_ROSTERS_FOR_TIMESHEETS); workingRosterEventTitleFieldName = (workingRosterView != null) ? workingRosterView.GetEventTitleFieldName(calendarScope) : FieldNames.START_DATE; workingRosterEventLocationFieldName = (workingRosterView != null) ? workingRosterView.GetEventLocationFieldName(calendarScope) : FieldNames.END_DATE; } // init Calendar Items var items = new SPCalendarItemCollection(); items.AddRange(expandedEvents.Select(x => new SPCalendarItem() { DisplayFormUrl = (defaultEventType == x.EventTypeId) ? defaultDispFormUrl : workingRoster_DispFormUrl, CalendarType = calendarType, ItemID = x.InstanceID, StartDate = x.StartDate, EndDate = x.EndDate, hasEndDate = true, Title = ((IDictionary <string, object>)x.OriginalItem.RosterEventProperties)[(defaultEventType == x.EventTypeId) ? eventTitleFieldName : workingRosterEventTitleFieldName].ToString(), Location = ((IDictionary <string, object>)x.OriginalItem.RosterEventProperties)[(defaultEventType == x.EventTypeId) ? eventLocationFieldName : workingRosterEventLocationFieldName].ToString(), IsAllDayEvent = x.OriginalItem.GetIsAllDayEvent(), IsRecurrence = x.OriginalItem.GetIsRecurrence() }).ToList()); return(items); }
public override string ToString() { return(string.Format("TemplatePath={0}&TemplateList={1}&TemplateName={2}&TemplateContentFieldName={3}", SPEncode.UrlEncode(TemplatePath), SPEncode.UrlEncode(TemplateList), SPEncode.UrlEncode(TemplateName), SPEncode.UrlEncode(TemplateContentFieldName))); }
public static string ConstructQueryString(this NameValueCollection parameters) { return(string.Join("&", (from string name in parameters select String.Concat(name, "=", SPEncode.UrlEncode(parameters[name]))).ToArray())); }
protected void FillData(string pagingInfo, string sortColumn, bool sortAscending) { int currentPage = Convert.ToInt32(ViewState["CurrentPage"]); int rowCount = ItemCount; string columnValue; string nextPageString = "Paged=TRUE&p_ID={0}&p_" + sortColumn + "={1}"; string previousPageString = "Paged=TRUE&PagedPrev=TRUE&p_ID={0}&p_" + sortColumn + "={1}"; SPListItemCollection collection; SPList list = SPContext.Current.List; List <NewsItem> catNews = NewsService.GetNewsByCategory(list, rowCount, pagingInfo, out collection); if (catNews != null && catNews.Count > 0) { rptNews.DataSource = catNews; rptNews.DataBind(); //identify if this is a call from next or first if (collection != null && collection.ListItemCollectionPosition != null) { if (collection.Fields[sortColumn].Type == SPFieldType.DateTime) { columnValue = SPEncode.UrlEncode(Convert.ToDateTime(collection[collection.Count - 1][sortColumn]).ToUniversalTime().ToString("yyyyMMdd HH:mm:ss")); } else { columnValue = SPEncode.UrlEncode(Convert.ToString(collection[collection.Count - 1][sortColumn])); } nextPageString = string.Format(nextPageString, collection[collection.Count - 1].ID, columnValue); } else { nextPageString = string.Empty; } if (currentPage > 1) { if (collection.Fields[sortColumn].Type == SPFieldType.DateTime) { columnValue = SPEncode.UrlEncode(Convert.ToDateTime(collection[0][sortColumn]).ToUniversalTime().ToString("yyyyMMdd HH:mm:ss")); } else { columnValue = SPEncode.UrlEncode(Convert.ToString(collection[0][sortColumn])); } previousPageString = string.Format(previousPageString, collection[0].ID, columnValue); } else { previousPageString = string.Empty; } if (string.IsNullOrEmpty(nextPageString)) { ibtnNext.Visible = false; } else { ibtnNext.Visible = true; } if (string.IsNullOrEmpty(previousPageString)) { ibtnPrev.Visible = false; } else { ibtnPrev.Visible = true; } ViewState["Previous"] = previousPageString; ViewState["Next"] = nextPageString; lblPage.Text = ((currentPage - 1) * rowCount) + 1 + " - " + (currentPage * rowCount - (rowCount - catNews.Count)); } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (ControlMode == SPControlMode.Display) { return; } EnsureChildControls(); var key = "DialogFieldScript_" + ID; if (!Page.ClientScript.IsClientScriptBlockRegistered(typeof(DialogList), key)) { var dataGridString = DataGrid != null?SPEncode.UrlEncode(DataGrid.ToString()) : string.Empty; const string urlFormat = "{0}/DialogBox.aspx?IsDlg=1&Choices={1}&AllowMultipleValues={2}&AllowFillInValue={3}&LookupList={4}&LookupField={5}&WhereCondition={6}&SeparateCharacter={7}&CombineDataSources={8}&MultiLine={9}&EnableQuickSearch={10}&LookupWithHighPermission={11}&DataGrid={12}"; var url = string.Format(urlFormat, Web.Url, SPEncode.UrlEncode(Choices), AllowMultipleValues, AllowFillInValue, SPEncode.UrlEncode(LookupList), SPEncode.UrlEncode(LookupField), SPEncode.UrlEncode(WhereCondition), SPEncode.UrlEncode(SeparateCharacter), CombineDataSources, MultiLine, EnableQuickSearch, LookupWithHighPermission, dataGridString); hdfDialogSectionUrl.Value = url; var script = new StringBuilder(); script.AppendFormat("function dfShowModalDialog_{0}(){{", ClientID); script.AppendFormat("var url = $('#{0}').val();", hdfDialogSectionUrl.ClientID); script.AppendFormat("var value = $('#{0}').val();", ClientID); script.Append("value = encodeURIComponent(value);"); script.Append("url = url + '&Value=' + value;"); script.Append("var options = SP.UI.$create_DialogOptions();"); script.Append("options.url = url;"); script.Append("options.allowMaximize = false;"); script.Append("options.showMaximized = false;"); script.AppendFormat("options.title = '{0}';", DialogTitle); script.AppendFormat( "options.dialogReturnValueCallback = Function.createDelegate(null, dfOnDialogCloseCallback_{0});", ID); script.Append("var dialog = SP.UI.ModalDialog.showModalDialog(options);"); script.Append("return false;"); script.Append("}"); script.AppendFormat("function dfOnDialogCloseCallback_{0}(result, target){{", ID); script.Append("if(result == SP.UI.DialogResult.OK){"); script.AppendFormat("$('#{0}').val(target);", ClientID); if (IsLookupField) { script.Append("var split = target.split(';#');"); script.Append("var values = [];"); script.Append("for(i=0;i<=split.length;i++){"); script.Append("if(i%2 != 0){values.push(split[i]);}"); script.Append("}"); script.AppendFormat(MultiLine ? "$('#{0}_Input').val(values.join('\\r\\n'));" : "$('#{0}_Input').val(values.join('; '));", ClientID); } else { script.AppendFormat(MultiLine ? "$('#{0}_Input').val(target.replace(/;#/g, '\\r\\n'));" : "$('#{0}_Input').val(target.replace(/;#/g, '; '));", ClientID); } if (AutoPostBack) { script.Append(Page.ClientScript.GetPostBackEventReference(this, "")); } script.Append("}"); script.Append("}"); if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack) { ScriptManager.RegisterStartupScript(Page, GetType(), key, script.ToString(), true); } else { Page.ClientScript.RegisterClientScriptBlock(typeof(DialogList), key, script.ToString(), true); } } if (focus) { Page.ClientScript.RegisterStartupScript(GetType(), "Focus", string.Format( "$(document).ready(function(){{$('#{0}_ShowModalDialog').focus();}});", ClientID), true); } }