public List <DataSourceShell> GetFolderByPage(int pageSize, int pageindex, out bool isEndPage) { ShellAPI.IEnumIDList shllEnum = null; IntPtr ptrIDLChild = IntPtr.Zero; Int32 isGotChild = 0; List <DataSourceShell> lst = new List <DataSourceShell>(); LogHelper.DebugFormat("shell GetFolderByPage ==>{0}", this.ParsingName); if (this._blibrary) //support for windows 7 library { #region For library ShellAPI.IShellItem psi; if (ShellAPI.SHCreateShellItem(IntPtr.Zero, null, PIDL, out psi) == 0) { Int32 length = 0; if (ShellAPI.SHLoadLibraryFromItem(psi, ref length) == 0) { for (int i = 0; i <= length; i++) { ShellAPI.IShellItem psiarry; if (ShellAPI.SHGetShellItemsAt(psi, i, out psiarry) == 0) { DataSourceShell shItem = new DataSourceShell(psiarry); lst.Add(shItem); } } isEndPage = true; return(lst); } } #endregion } #region init isEndPage = false; // Get the IEnumIDList interface pointer. ShellAPI.SHCONTF flags = ShellAPI.SHCONTF.SHCONTF_FOLDERS; if (shllEnum != null) { Marshal.ReleaseComObject(shllEnum); } uint result = ShellFolder.EnumObjects(IntPtr.Zero, flags , out shllEnum); if (result != 0) { isEndPage = true; LogHelper.Debug("result != 0 ==> true"); return(null); } #endregion #region reset enum ptrIDLChild = IntPtr.Zero; isGotChild = 0; shllEnum.Reset(); #endregion #region skip pageIndex*pageSize // Grab the first enumeration. for (int i = 0; i <= ((pageindex - 1) * pageSize); i++) { // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(ptrIDLChild); ptrIDLChild = IntPtr.Zero; isGotChild = 0; // Grab the next item. shllEnum.Next(1, out ptrIDLChild, out isGotChild); } #endregion LogHelper.Debug("enum ....."); #region enum item int itemIndex = 0; while (itemIndex < pageSize) { SpecialFolderType specialFolderType = CheckSpecialFolderType(shellFolder, ptrIDL, ptrIDLChild); if (specialFolderType != SpecialFolderType.Internet && specialFolderType != SpecialFolderType.RecycleBin && specialFolderType != SpecialFolderType.MyComputerControlPanel && specialFolderType != SpecialFolderType.DesktopControlPanel && (SpecialFolderType != SpecialFolderType.MyComputer || (specialFolderType != SpecialFolderType.MyDocuments && specialFolderType != SpecialFolderType.SharedDocuments)) ) { LogHelper.DebugFormat("enum-1 : {0}", ptrIDLChild); // Create the new ShellItem object. DataSourceShell shItem = new DataSourceShell(shellRoot, ptrIDLChild, this, false, specialFolderType); if (shItem.IsFolder && !shItem.IsStream) { lst.Add(shItem); } LogHelper.DebugFormat("enum : {0}", shItem.ParsingName); } // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(ptrIDLChild); ptrIDLChild = IntPtr.Zero; isGotChild = 0; // Grab the next item. shllEnum.Next(1, out ptrIDLChild, out isGotChild); if (ptrIDLChild.Equals(IntPtr.Zero) && isGotChild == 0) { LogHelper.Debug("ptrIDLChild.Equals(IntPtr.Zero) && iGotChild == 0 ==> true"); isEndPage = true; break; } itemIndex++; } #endregion LogHelper.Debug("enum <=="); #region sort item // AH: If _getfolders flag is true, sort treeview items. if (this.SpecialFolderType != SpecialFolderType.MyComputer) { List <DataSourceShell> tempLst = new List <DataSourceShell>(); IComparer <DataSourceShell> comparer = new SortAscending(); for (int i = 0; isRoot && i < lst.Count; i++) { if (lst[i].SpecialFolderType == SpecialFolderType.MyComputer || lst[i].SpecialFolderType == SpecialFolderType.DesktopControlPanel || lst[i].SpecialFolderType == SpecialFolderType.Network || lst[i].SpecialFolderType == SpecialFolderType.MyDocuments || lst[i].SpecialFolderType == SpecialFolderType.SharedDocuments || lst[i].SpecialFolderType == SpecialFolderType.CurrentUserProfile ) { tempLst.Add(lst[i]); lst.RemoveAt(i); i--; } } lst.Sort(comparer); for (int i = 0; isRoot && i < tempLst.Count; i++) { lst.Insert(i, tempLst[i]); } } #endregion LogHelper.Debug("enum end=="); return(lst); }
protected override void Render(HtmlTextWriter writer) { if (ItemTemplate == "") { return; } writer.Write(HeaderTemplate); // Filters if (Filters == null) { Filters = new Dictionary <string, string>(); } var additionalFilters = new Dictionary <string, string>(); additionalFilters.Add("Records", PageSize.ToString()); additionalFilters.Add("PageIndex", PageIndex.ToString()); additionalFilters.Add("Rowsize", RowSize.ToString()); additionalFilters.Add("SortBy", SortBy); additionalFilters.Add("SortAscending", SortAscending.ToString()); // Currently Not Used by the SPROC var filterUser = Filters.ContainsKey("UserId") && Filters["UserId"] != null ? new UserInfo() { UserID = int.Parse(Filters["UserId"]) } : new UserInfo() { PortalID = _currentUser.PortalID }; var role = Filters.ContainsKey("RoleId") && Filters["RoleId"] != null ? new UserRoleInfo() { RoleID = int.Parse(Filters["RoleId"]) } : null; var relationship = Filters.ContainsKey("RelationshipTypeId") && Filters["RelationshipTypeId"] != null ? new RelationshipType() { RelationshipTypeId = int.Parse(Filters["RelationshipTypeId"]) } : null; foreach (var filter in Filters.Where(filter => !additionalFilters.ContainsKey(filter.Key))) { additionalFilters.Add(filter.Key, filter.Value); } var row = 0; var users = new DataTable(); //users.Load(_relationshipController.GetUsersAdvancedSearch(_currentUser, filterUser, role, relationship, Filters, additionalFilters)); if (users.Rows.Count > 0) { foreach (DataRow user in users.Rows) { //Row Header writer.Write(string.IsNullOrEmpty(AlternatingRowHeaderTemplate) || row % 2 == 0 ? RowHeaderTemplate : AlternatingRowHeaderTemplate); var tokenReplace = new TokenReplace(); var tokenKeyValues = new Dictionary <string, string>(); foreach (var col in user.Table.Columns.Cast <DataColumn>().Where(col => !tokenKeyValues.ContainsKey(col.ColumnName))) { tokenKeyValues.Add(col.ColumnName, user[col.ColumnName].ToString()); } var listItem = string.IsNullOrEmpty(AlternatingItemTemplate) || row % 2 == 0 ? ItemTemplate : AlternatingItemTemplate; listItem = tokenReplace.ReplaceEnvironmentTokens(listItem, tokenKeyValues, "Member"); writer.Write(listItem); //Row Footer writer.Write(string.IsNullOrEmpty(AlternatingRowFooterTemplate) || row % 2 == 0 ? RowFooterTemplate : AlternatingRowFooterTemplate); row++; } } writer.Write(FooterTemplate); }
/// <summary> /// Gets the page. /// </summary> /// <param name="getNextPage">if set to <c>true</c> [get next page].</param> /// <param name="pageSize">Size of the page.</param> /// <returns></returns> List <DataSourceShell> GetPage(ShellAPI.IEnumIDList pEnum) { IntPtr pIDLChild = IntPtr.Zero; Int32 iGotChild = 0; List <DataSourceShell> lst = new List <DataSourceShell>(); pEnum.Next(1, out pIDLChild, out iGotChild); while (!pIDLChild.Equals(IntPtr.Zero) && iGotChild == 1) { SpecialFolderType specialFolderType = CheckSpecialFolderType(shellFolder, ptrIDL, pIDLChild); if (specialFolderType != SpecialFolderType.Internet && specialFolderType != SpecialFolderType.RecycleBin && specialFolderType != SpecialFolderType.MyComputerControlPanel && specialFolderType != SpecialFolderType.DesktopControlPanel && (SpecialFolderType != SpecialFolderType.MyComputer || (specialFolderType != SpecialFolderType.MyDocuments && specialFolderType != SpecialFolderType.SharedDocuments)) ) { // Create the new ShellItem object. DataSourceShell shItem = new DataSourceShell(shellRoot, pIDLChild, this, false, specialFolderType); if (shItem.IsFolder && !shItem.IsStream) { lst.Add(shItem); } } // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(pIDLChild); pIDLChild = IntPtr.Zero; iGotChild = 0; // Grab the next item. pEnum.Next(1, out pIDLChild, out iGotChild); } if (this.SpecialFolderType != SpecialFolderType.MyComputer) { List <DataSourceShell> tempLst = new List <DataSourceShell>(); IComparer <DataSourceShell> comparer = new SortAscending(); for (int i = 0; isRoot && i < lst.Count; i++) { if (lst[i].SpecialFolderType == SpecialFolderType.MyComputer || lst[i].SpecialFolderType == SpecialFolderType.DesktopControlPanel || lst[i].SpecialFolderType == SpecialFolderType.Network || lst[i].SpecialFolderType == SpecialFolderType.MyDocuments || lst[i].SpecialFolderType == SpecialFolderType.SharedDocuments || lst[i].SpecialFolderType == SpecialFolderType.CurrentUserProfile ) { tempLst.Add(lst[i]); lst.RemoveAt(i); i--; } } lst.Sort(comparer); for (int i = 0; isRoot && i < tempLst.Count; i++) { lst.Insert(i, tempLst[i]); } } return(lst); }