internal virtual void PrintBody(StreamWriter writer, HttpRequest request, IDirectory directory, ICollection dirs, ICollection files ) { writer.WriteLine("<h2>Index of " + HttpWebServer.GetDirectoryPath(directory) + "</h2>"); if (directory.Parent != null) { writer.WriteLine("<a href=\"..\">[..]</a><br>"); } foreach (IDirectory dir in dirs) { //if(dir is IPhysicalResource) // if((File.GetAttributes((dir as IPhysicalResource).Path) & FileAttributes.Hidden) != 0) // continue; writer.WriteLine("<a href=\"" + UrlEncoding.Encode(dir.Name) + "/\">[" + dir.Name + "]</a><br>"); } foreach (IFile file in files) { //if(file is IPhysicalResource) // if((File.GetAttributes((file as IPhysicalResource).Path) & FileAttributes.Hidden) != 0) // continue; writer.WriteLine("<a href=\"" + UrlEncoding.Encode(file.Name) + "\">" + file.Name + "</a><br>"); } }
string MakeLinkPath(IDirectory directory, HttpRequest request) { StringBuilder sb = new StringBuilder(); ArrayList pathList = new ArrayList(); for (IDirectory dir = directory; dir != null; dir = dir.Parent) { pathList.Add(dir.Name); } pathList.RemoveAt(pathList.Count - 1); pathList.Reverse(); sb.Append("<a href=\"" + request.Uri.Scheme + "://" + request.Uri.Host); if (request.Uri.Port != 80) { sb.Append(":" + request.Uri.Port); } sb.Append("/\">"); sb.Append(request.Uri.Host + "</a>"); if (pathList.Count > 0) { sb.Append(" - "); } StringBuilder reassembledPath = new StringBuilder(); for (int i = 0; i < pathList.Count; i++) { string path = pathList[i] as string; sb.Append("<a href=\"/"); reassembledPath.Append(UrlEncoding.Encode(path)); reassembledPath.Append("/"); sb.Append(reassembledPath.ToString()); sb.Append("\">"); sb.Append(path); if (i < pathList.Count - 1) { sb.Append("</a>/"); } else { sb.Append("</a>"); } } return(sb.ToString()); }
/// <summary> /// Returns the <see cref="Uri"/> of a specified resource. /// </summary> /// <param name="resource">An <see cref="IResource"/> specifying the file for which to return a <see cref="Uri"/>.</param> /// <returns>A <see cref="Uri"/> to the specified file.</returns> public Uri GetUrl(IResource resource) { string url = UrlEncoding.Encode(GetDirectoryPath(resource.Parent).TrimStart('/') + resource.Name); if (resource is IDirectory) { url += '/'; } return(new Uri(ServerUri, url)); }
/// <summary> /// Parse a query from a given string. /// </summary> /// <param name="query">The query string to parse from.</param> /// <param name="urlEncoded">A value indicating whether the string is URL encoded or not.</param> public UriQuery(string query, bool urlEncoded) { for (int i = 0; i < query.Length; i++) { int start = i; int equalIndex = -1; while (i < query.Length) { if (query[i] == '=') { if (equalIndex < 0) { equalIndex = i; } } else if (query[i] == '&') { break; } i++; } string name; string value; if (equalIndex < 0) { name = query.Substring(start, i - start); value = string.Empty; } else { name = query.Substring(start, equalIndex - start); value = query.Substring(equalIndex + 1, (i - equalIndex) - 1); } if (urlEncoded) { this.Add(UrlEncoding.Decode(name), UrlEncoding.Decode(value)); } else { this.Add(name, value); } if (i == query.Length - 1 && query[i] == '&') { this.Add(null, string.Empty); } } }
static string[] GetUriPathNodes(string absolutePath) { ArrayList nodes = new ArrayList(); string path = absolutePath.Replace('\\', '/'); if (path.Length <= 1) { return new string[] { UrlEncoding.Decode(path) } } ; // return new string[] {path}; int start = 0; for (int i = 0; i < path.Length; i++) { if (path[i] == '/') { while (i < path.Length && path[i] == '/') { i++; } nodes.Add(UrlEncoding.Decode(path.Substring(start, i - start))); //nodes.Add(path.Substring(start, i-start)); start = i; } } if (start != path.Length) { nodes.Add(UrlEncoding.Decode(path.Substring(start, path.Length - start))); } //nodes.Add(path.Substring(start, path.Length-start)); return(nodes.ToArray(typeof(string)) as string[]); }
public void WriteHtml(StreamWriter writer, ResourceColumn[] columns) { try { if (path != null) { if ((File.GetAttributes(path) & FileAttributes.Hidden) != 0) { return; } } } catch (IOException) { } writer.WriteLine("<tr>"); foreach (ResourceColumn column in columns) { writer.Write(GetColumnTd(column)); switch (column) { case ResourceColumn.Created: if (path != null) { if (Created != DateTime.MinValue) { writer.Write(Created.ToString()); } } break; case ResourceColumn.Modified: if (path != null) { if (Modified != DateTime.MinValue) { writer.Write(Modified.ToString()); } } break; case ResourceColumn.Size: if (!isDir) { if (path != null) { if (Size != -1) { writer.Write(ReadableDataLength.Calculate(Size)); } } } break; case ResourceColumn.Name: writer.WriteLine("<a href=\"" + UrlEncoding.Encode(resource.Name) + (isDir ? "/\">[" : "\">") + resource.Name + (isDir ? "]" : "") + "</a>"); break; } writer.WriteLine("</td>"); } writer.WriteLine("</tr>"); }