-
-
Save harshbaid/7a570be8255e160d0d84ab197f6a4c3c to your computer and use it in GitHub Desktop.
Sitecore Temp Folder Browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title>Sitecore Temp Folder Browser</title> | |
<link rel="Stylesheet" type="text/css" href="/sitecore/shell/themes/standard/default/WebFramework.css" /> | |
<link rel="Stylesheet" type="text/css" href="./default.css" /> | |
</head> | |
<body> | |
<script runat="server"> | |
private const string TEMP_FOLDER_PATH = @"C:\inetpub\wwwroot\Sitecore\temp\"; | |
private const int MAX_FILE_COUNT = 10; | |
private void Scan(string path) { | |
string maxFileCountString = GetQueryString("maxFileCount"); | |
int maxFileCount = MAX_FILE_COUNT; | |
if (!string.IsNullOrEmpty(maxFileCountString) && !int.TryParse(maxFileCountString, out maxFileCount)) | |
{ | |
Response.Write("<li><span style='color:red'>Invalid value for the <i>maxFileCount</i> parameter. It must be an integer.</span></li>"); | |
} | |
else | |
{ | |
if (!System.IO.Directory.Exists(path)) | |
{ | |
Response.Write("<li><span style='color:red'>Invalid path. The path does not exist: " + path + "</span></li>"); | |
} | |
else | |
{ | |
string ignoredFolderNamesString = GetQueryString("ignoreFolderNames"); | |
string[] ignoredFolderNames; | |
if (!string.IsNullOrEmpty(ignoredFolderNamesString)) | |
{ | |
ignoredFolderNames = ignoredFolderNamesString.Split(','); | |
} | |
else | |
{ | |
ignoredFolderNames = new string[0]; | |
} | |
if (path.EndsWith("\\") || path.EndsWith("/")) | |
{ | |
path = path.Substring(0, path.Length - 1); | |
} | |
ScanRecursive(path, maxFileCount, ignoredFolderNames); | |
} | |
} | |
} | |
private void ScanRecursive(string path, int maxFileCount, string[] ignoredFolderNames) | |
{ | |
Response.Write("<li>"); | |
Response.Write("<a href='?maxFileCount=" + maxFileCount + "&ignoreFolderNames=" + string.Join(",", ignoredFolderNames) + "&subPath=" + path.Replace(TEMP_FOLDER_PATH, string.Empty) + "'>"); | |
Response.Write(System.IO.Path.GetFileName(path)); | |
Response.Write("</a>"); | |
Response.Write("</li>"); | |
if (!ignoredFolderNames.Any(s => s.Equals(System.IO.Path.GetFileName(path), StringComparison.OrdinalIgnoreCase))) { | |
Response.Write("<ul>"); | |
foreach (var directory in System.IO.Directory.GetDirectories(path)) { | |
ScanRecursive(directory, maxFileCount, ignoredFolderNames); | |
} | |
int count = 0; | |
foreach (var file in System.IO.Directory.GetFiles(path)) { | |
if (++count > maxFileCount) { | |
Response.Write("<li>...</li>"); | |
break; | |
} | |
Response.Write("<li><i>"); | |
Response.Write("<a href='" + file.Replace(TEMP_FOLDER_PATH, "/-/temp/") + ".aspx' target='_blank'>"); | |
Response.Write(System.IO.Path.GetFileName(file)); | |
Response.Write("</a>"); | |
Response.Write("</i></li>"); | |
} | |
Response.Write("</ul>"); | |
} | |
else | |
{ | |
Response.Write("<ul><li><i>(ignored due to query string)</i></li></ul>"); | |
} | |
} | |
private string GetQueryString(string key) { | |
return Request.QueryString[key]; | |
} | |
</script> | |
<form id="Form1" runat="server" class="wf-container"> | |
<div class="wf-content"> | |
<h1>Sitecore Temp Folder Browser</h1> | |
<% string fullPath = TEMP_FOLDER_PATH + GetQueryString("subPath"); %> | |
<h4><%= fullPath %></h4> | |
<ul> | |
<% | |
Scan(fullPath); | |
%> | |
</ul> | |
</div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment