public static string CleanUnixCrLf(string textIn) { //firefox only uses Lf and not CrLf return System.Text.RegularExpressions.Regex.Replace(textIn, "([^\r])[\n]", "$1\r\n"); }
Useful tidbits related to software development, that I think might be of use or interest to everyone else (or to me when I forget what I did!)
public static string CleanUnixCrLf(string textIn) { //firefox only uses Lf and not CrLf return System.Text.RegularExpressions.Regex.Replace(textIn, "([^\r])[\n]", "$1\r\n"); }
Option Strict Off Option Explicit Off Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Public Module AttachToIIS Sub Attach() Try Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default") Dim dbgeng(3) As EnvDTE80.Engine dbgeng(0) = trans.Engines.Item("Managed") dbgeng(1) = trans.Engines.Item("Native") dbgeng(2) = trans.Engines.Item("T-SQL") Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, Environment.MachineName).Item("w3wp.exe") proc2.Attach2(dbgeng) Catch ex As System.Exception MsgBox(ex.Message) End Try End Sub End ModuleIf you get the error 'Invalid Index' it generally means that IIS has not loaded the application since a recompile, so you need to refresh the page in your browser first to reload it.
<%@ Import Namespace="eCommerceFramework.BLL.EntityExtensions" %> --------------- <asp:TemplateField HeaderText="Price"> <ItemTemplate> <%# FormatCurrency(DirectCast(Container.DataItem, DDL.DTOs.ShopBundle).TotalPrice(),2) %> </ItemTemplate> </asp:TemplateField>Generally speaking, I wouldn't imagine you would be 2 way data-binding on an extension method, but if you need to make the value retreivable, put it into a runat="server" control (label/textbox) and give it an ID you can use for FindControl.
<div> <div class="targetContent"> Something in here <div> Something else in here</div> </div> </div>Using standard regular expressions, searching for <div class="targetContent"> to </div> can work in two ways. Non-greedy mode, matches on the </div> of the inner div. In greedy mode, it matches all the way to end of the outer div. What I wanted to do, is match on the last </div> that makes the tags balance, which can be done using balancing groups! C# Code:
pattern = "<div class=\"targetContent\">.*?((?<TAG><div).*?(?<-TAG></div>))?(?(TAG)(?!))</div>";Effectively, what the expression does is:
var distinctByWeekNum = from e in allUserEntries group e by e.WeekNumber into g select g.First();The above example basically selects all objects that are distinct based on the 'WeekNumber', by first grouping items with the same 'WeekNumber' together and then selecting only the first item from each group (thus dropping any duplicates).
<bindings> <webHttpBinding> <binding name="webHttpsBinding"> <security mode="Transport"></security> </binding> </webHttpBinding> </bindings> <services> <service name="WebNs.xyzService"> <endpoint address="" behaviorConfiguration="WebNs.xyzServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webHttpsBinding" contract="WebNs.xyzService" /> </service>This configures your service to serve up over HTTPS. Make sure you add the HTTPS binding in IIS for this to work!
<asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Example Button" ImageUrl="~/images/button.png" />This is fine for most cases. However, when using URL rewriting (via HttpHandlers) it can become a problem, since ASP.NET will calculate the path to the resource based on the location of the physical page it is rendering (not the page requesed in the browser [RawUrl]). If the resource is in a directory below the page directory, then it will render a relative path to the HTML, (and not an absolute path from the app root). When your browser sees a relative path in the HTML it appends that to the current working directory to retreive the resource, which for a page being served up via a rewrite, is probably the wrong directory. For example, imagine you have the following directory structure: /MyButtonPage.aspx /images/button.png /subdir/page-served-by-httphandler-mapping-to-mybuttonpage.aspx If you view '/MyButtonPage.aspx' (containing the code from above) the output path to the image would be 'images/button.png'. Your browser will therefore retreive '/images/button.png' which is correct. However, if you view '/subdir/page-served-by-httphandler-mapping-to-mybuttonpage.aspx' (which rewrites internally the '/MyButtonPage.aspx') then ASP.NET will again render the image path as 'images/button.png' (since it is relative to the 'MyButtonPage.aspx' which was rendered internally). Your browser will now try to retrieve, '/subdir/images/button.png' which does not exist. A workaround for this problem is to not use the tilde mechanism and instead reference the absolute path to the resource in the code. e.g.
<asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Example Button" ImageUrl="/images/button.png" />However, this will reference from the website root, not the application root, so be careful if your site runs as a virtual application within another site.
Imports System.Text.RegularExpressions Public Class UrlEncoder Public Shared Function EncodeRewriteUrl(ByVal inputString As String) As String Dim url As String = Regex.Replace(System.Web.HttpUtility.HtmlDecode(inputString.Replace(" ", "-")), "[^a-zA-Z0-9\-]", "") While url.Contains("--") url = url.Replace("--", "-") End While Return url End Function End ClassThe idea here is that you pass in the text you want to use as your URL, and you receive a hyphenated URL containing only URL safe characters ready for use with your rewriting engine. Example: if.. pageId=1 pageTitle="A page about 'dogs' and 'cats' (also other things)" and.. pageUrl=UrlEncoder.EncodeRewriteUrl(pageTitle & "-" & pageId & ".aspx") then.. The page URL would be: A-page-about-dogs-and-cats-also-other-things-1.aspx
if not IsPostback then try Dim file As String = "blog-content.html" Response.Cache.SetLastModified(IO.File.GetLastWriteTime(Server.MapPath(file))) dim content as string=IO.File.ReadAllText(Server.MapPath(file)) content = content.Substring(content.IndexOf("<body>") + "<body>".Length, content.LastIndexOf("</body>") - content.IndexOf("<body>") - "<body>".Length) content = content.Remove(content.IndexOf("<iframe"), content.IndexOf("</iframe>") + "</iframe>".Length - content.IndexOf("<iframe")) lblContent.Text=content 'load the labels dim labelFiles() as string=IO.Directory.GetFiles(Server.MapPath("labels")) ddlCats.Items.Clear ddlCats.Items.Add(New ListItem("--Jump To Category--","")) for each filename as string in labelFiles dim url as string=filename.substring(filename.lastindexof("\")+1,filename.length-filename.lastindexof("\")-1) ddlCats.Items.Add(New ListItem(url.replace(".html",""),url)) next catch ex as exception lblContent.Text="Error: " & ex.Message end tryMy site only uses this method for the index page, but you could extend this idea even further to display all blog pages within your custom ASP.NET / masterpage site, by putting the /blog directory under a custom HttpHandler (if your server allows this) and rewriting the URL to your ASP.NET page. Also I would suggest using regular expressions for filtering the HTML if your server supports it. -- Edit: 25/11/2008 I have now improved the integration by using the HTML generated by my masterpage as the template on Blogger.com, so all the pages look like you are on my website. This means I could refine the above process of finding the correct content for each placeholder, (with the addition of a seperate placeholder for the sidebar) as the divs that contain the data have specific class names. I have also created two more aspx pages, "index by date" and "index by category" - the code behind for these simply enumerate the "archives"/"labels" folders on the server, (the same as my drop down box above). Additionally, these pages open each .html file to parse the content for all of the post titles and permalinks to create the list of links for each date/label. -- Edit: 18/10/2010 Since my blog no longer uses Blogger due to FTP publishing being cancelled this code is now redundant.