Skip to main content

Posts

Making Sense of ASP.NET Paths

Nice article found on the following path about Asp.Net Paths. Ref: http://weblog.west-wind.com/posts/2009/Dec/21/Making-Sense-of-ASPNET-Paths Request Property Description and Value ApplicationPath Returns the web root-relative logical path to the virtual root of this app. /webstore/ PhysicalApplicationPath Returns local file system path of the virtual root for this app. c:\inetpub\wwwroot\webstore PhysicalPath Returns the local file system path to the current script or path . c:\inetpub\wwwroot\webstore\admin\paths.aspx Path FilePath CurrentExecutionFilePath All of these return the full root relative logical path to the script page including path and scriptname. CurrentExcecutionFilePath will return the ‘current’ request path after a Transfer/Execute call while FilePath will always return the original request’s p...

How to get all html img tag (image) src uri from a html content?

public List<string> GetAllImageUri(string content) {     string pattern = @"<(?<Tag_Name>img)\b[^>]*?\b(?<URL_Type>(?(1)src))\s*=\s*(?:""(?<URL>(?:\\""|[^""])*)""|'(?<URL>(?:\\'|[^'])*)')";       // Getting collection of matched uri.     MatchCollection imageUriCollection = Regex.Matches(content, pattern, RegexOptions.IgnoreCase);       if (imageUriCollection.Count > 0)     {           return imageUriCollection.Cast<Match>() .Select(x => x.Groups["URL"].Value) .ToList();     }     return null; }

Javascript : How to insert text into textbox or textare or input elements at teh cursor position

function insertAtCursor(myField, myValue) { // For IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } // For MOZILLA and others else if (myField.selectionStart || myField.selectionStart == '0' ) { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.selectionStart = startPos + myValue.length; myField.selectionEnd = startPos + myValue.length; } else { myField.value += myValue; } }

How to convert Dictionary to a comma separated csv string in c#?

the following function will take the list of dictionary items to a comma separated csv string. public string ConvertToCSV(List<Dictionary<string, string>> items) {     if (!items.Any()) return string.Empty;     StringBuilder writer = new StringBuilder();     // Generating Header.     List<string> headers = items[0].Keys.Select(x => x).OrderBy(x => x).ToList();     writer.AppendLine(string.Join(", ", headers.Select(h => h)));     // Generating content.     foreach (var item in items)     writer.AppendLine(string.Join(", ", headers.Select(h => item[h])));     return writer.ToString(); }