當前位置: 首頁>>代碼示例>>C#>>正文


C# StorageFolder.GetParentAsync方法代碼示例

本文整理匯總了C#中Windows.Storage.StorageFolder.GetParentAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# StorageFolder.GetParentAsync方法的具體用法?C# StorageFolder.GetParentAsync怎麽用?C# StorageFolder.GetParentAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Storage.StorageFolder的用法示例。


在下文中一共展示了StorageFolder.GetParentAsync方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GenerateGallery

        /// <summary>
        /// Generates html for the gallery
        /// </summary>
        /// <param name="folder">Folder to read the pictures from</param>
        /// <param name="pageNumber">Page starting from 1</param>
        /// <param name="pageSize">Number of pictures on each page</param>
        /// <returns></returns>
        public async Task<string> GenerateGallery(StorageFolder folder, int pageNumber, int pageSize)
        {
            // Don't allow negatives
            if (pageNumber < 1) pageNumber = 1;
            if (pageSize < 1) pageSize = 1;

            var subFolders = await folder.GetFoldersAsync();
            var parentFolder = await folder.GetParentAsync();

            // JavaScript code for toggling the subfolder list
            string html = "";
            html += "<script type='text/javascript'>" +
                "function toggleSubfolderList(){"+
                "var folderNavPane = document.getElementById('folder_nav_pane');" +
                "if(folderNavPane.style.display == 'block') folderNavPane.style.display = 'none';" +
                "else folderNavPane.style.display = 'block'" +
                "}" +
                "</script>";

            html += "<table>";
            html += "<tr><td>";
            // Create breadcrumbs for folder nav
            var temp = folder;
            string breadcrumbs = "<b>"+ ((subFolders.Count > 0) ? "<a onclick='toggleSubfolderList()' href='javascript:void(0);'>" + temp.Name + "</a>" : temp.Name) + "</b>";
            while(!temp.Path.Equals(rootFolder.Path, StringComparison.OrdinalIgnoreCase))
            {
                temp = await temp.GetParentAsync();
                string hyperlink = MakeHyperlink(temp.Name, "/gallery.htm?folder=" + WebUtility.UrlEncode(temp.Path), false);
                breadcrumbs = hyperlink + " > " + breadcrumbs;
            }
            html += breadcrumbs + "<br>";

            if (subFolders.Count > 0)
            {
                // Generate subfolder navigation pane
                html += "<div id='folder_nav_pane' style='display:none'>";
                html += "<ul>";
                foreach (StorageFolder subFolder in subFolders)
                {
                    html += "<li><a href='/gallery.htm?folder=" + WebUtility.UrlEncode(subFolder.Path) + "'>" + subFolder.Name + "</a></li>";
                }
                html += "</ul></div>";
            }

            html += "<br></td></tr>";

            // Get the files in current folder and subfolders
            var queryOptions = new QueryOptions();
            queryOptions.FolderDepth = FolderDepth.Deep;

            var results = folder.CreateFileQueryWithOptions(queryOptions);
            
            StorageFile[] sortedFiles = null;

            // Use cached files if we already got the files and we're navigating to the first page
            if (cachedFiles != null && pageNumber != 1)
            {
                sortedFiles = cachedFiles;
            }
            else
            {
                var files = await results.GetFilesAsync();
                sortedFiles = files.OrderByDescending((x) => x.DateCreated).ToArray();
                cachedFiles = sortedFiles;
            }

            if (sortedFiles.Length > 0)
            {
                // Create pages
                string pagesHtml = "<form>";
                html += "<tr><td>";
                int totalPages = (int)Math.Ceiling((double)sortedFiles.Length / pageSize);
                pagesHtml += "Pages: ";

                pagesHtml += "<select name='page' onchange='this.form.submit()'>";

                for (int i = 1; i <= totalPages; i++)
                {
                    pagesHtml += "<option value='" + i + "' " + ((i == pageNumber) ? "selected='selected'" : "") + ">" + i + "</option>";
                }
                pagesHtml += "</select>";
                pagesHtml += "<input type='hidden' name='folder' value='" + folder.Path + "' />";
                pagesHtml += "<input type='hidden' name='pageSize' value='30' />";
                pagesHtml += "</form>";

                html += pagesHtml;
                html += "<br></td></tr>";

                html += "<tr><td>";

                // Pick out the subset of files we need based on page
                int startIndex = (pageNumber - 1) * pageSize;
                for (int i = startIndex; i < startIndex + pageSize; i++)
//.........這裏部分代碼省略.........
開發者ID:jadeiceman,項目名稱:securitysystem-1,代碼行數:101,代碼來源:WebHelper.cs


注:本文中的Windows.Storage.StorageFolder.GetParentAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。