<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>.NET Blog</title><link>http://prosodev.com:80/net-blog</link><description>.NET Development Blog</description><item><title>Retrieve FileIcons from Path</title><link>http://prosodev.com:80/net-blog/retrieve-fileicons-from-path</link><description>&lt;h1&gt;Overview&lt;/h1&gt;</description><pubDate>Fri, 09 Jan 2015 06:51:19 GMT</pubDate><guid isPermaLink="true">http://prosodev.com:80/net-blog/retrieve-fileicons-from-path</guid><category>.NET</category><category>Winforms</category></item><item><title>How to print out &amp;nbsp; in cshtml files</title><link>http://prosodev.com:80/net-blog/how-to-print-out-nbsp-in-cshtml-files</link><description>&lt;h1&gt;Overview&lt;/h1&gt;
&lt;div class="blogoverview"&gt;A short snippet to display non-breaking space in CSHTML files. Hope this snippet in helpful.&lt;/div&gt;
&lt;p&gt;In some cases you have to write out &lt;strong&gt;&amp;amp;nbsp;&lt;/strong&gt; in cshtml files. The syntax for this you can find in the code snippet.&lt;/p&gt;
&lt;h1&gt;Snippet&lt;/h1&gt;
&lt;pre&gt;&lt;code class="csharp"&gt;@foreach (var a in new List&amp;lt;string&amp;gt; {"a", "b", "c"}) {
    @a
    @:&amp;amp;nbsp;
}
&lt;/code&gt;&lt;/pre&gt;</description><pubDate>Fri, 09 Jan 2015 02:46:00 GMT</pubDate><guid isPermaLink="true">http://prosodev.com:80/net-blog/how-to-print-out-nbsp-in-cshtml-files</guid><category>.NET</category><category>cshtml</category><category>ASP.NET</category></item><item><title>Compression of HTML-Output Module</title><link>http://prosodev.com:80/net-blog/compression-of-html-output-module</link><description>&lt;h1&gt;Overview&lt;/h1&gt;
&lt;div class="blogoverview"&gt;Some people like to have a compressed output of there WebForms or MVC-Pages in .NET. The following snippet shows such a compressor. It is not optimized for performance but you should see the principle behind. The compressor takes care of &amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;. You may also use this compressor to remove unwanted html snippets from your MVC or WebForm pages.&lt;/div&gt;
&lt;p&gt;Some people like to have a compressed output of there WebForms or MVC-Pages in .NET. The following snippet shows such a compressor. It is not optimized for performance but you should see the principle behind. The compressor takes care of &amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;. You may also use this compressor to remove unwanted html snippets from your MVC or WebForm pages.&lt;/p&gt;
&lt;h1&gt;Snippet&lt;/h1&gt;
&lt;h4&gt;Handler Module&lt;/h4&gt;
&lt;pre&gt;&lt;code class="csharp"&gt;using System.Linq;

namespace ProCompressor
{
    using System;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;

    public sealed class CompressionModule : IHttpModule
    {
        #region non public members

        private static void ContextBeginRequest(object sender, EventArgs e)
        {
            var app = sender as HttpApplication;
            if (app != null) if (app.Request.AcceptTypes != null &amp;amp;&amp;amp; app.Request.AcceptTypes.Contains("text/html") &amp;amp;&amp;amp; !app.Request.RawUrl.Contains("/Admin/")) app.Response.Filter = new CompressorBuffered(app.Response.Filter);
        }

        #endregion

        #region IHttpModule Members

        void IHttpModule.Dispose() { }
        void IHttpModule.Init(HttpApplication context) { context.BeginRequest += ContextBeginRequest; }

        #endregion

        #region Non Public Nested type: CompressorBuffered

        private class CompressorBuffered : Stream
        {
            #region fields

            private readonly MemoryStream memoryStream;
            private readonly Stream stream;

            #endregion

            #region constructors

            public CompressorBuffered(Stream stream)
            {
                this.stream = stream;
                this.memoryStream = new MemoryStream();
            }

            #endregion

            #region public properties

            public override bool CanRead { get { return this.stream.CanRead; } }
            public override bool CanSeek { get { return this.stream.CanSeek; } }
            public override bool CanWrite { get { return this.stream.CanWrite; } }
            public override long Length { get { return this.stream.Length; } }
            public override long Position { get; set; }

            #endregion

            #region public members

            public override void Close()
            {
                var data = this.memoryStream.ToArray();
                var content = Encoding.UTF8.GetString(data);
                content = CompressHtml(content);
                var output = Encoding.UTF8.GetBytes(content);
                this.stream.Write(output, 0, output.GetLength(0));
                this.stream.Close();
            }

            public override void Flush() { this.stream.Flush(); }
            public override int Read(byte[] buffer, int offset, int count) { return this.stream.Read(buffer, offset, count); }
            public override long Seek(long offset, SeekOrigin origin) { return this.stream.Seek(offset, origin); }
            public override void SetLength(long value) { this.stream.SetLength(value); }
            public override void Write(byte[] buffer, int offset, int count) { this.memoryStream.Write(buffer, offset, count); }

            #endregion

            #region non public members

            private static string CompressHtml(string content)
            {
                var matches = Regex.Matches(content, "&amp;lt;pre&amp;gt;.*&amp;lt;/pre&amp;gt;", RegexOptions.Singleline).Cast&amp;lt;Match&amp;gt;().ToList();
                content = Regex.Replace(content, "^\\s*", string.Empty, RegexOptions.Compiled | RegexOptions.Multiline);
                content = Regex.Replace(content, "\\r\\n", string.Empty, RegexOptions.Compiled | RegexOptions.Multiline);
                content = Regex.Replace(content, "\\n", string.Empty, RegexOptions.Compiled | RegexOptions.Multiline);
                content = Regex.Replace(content, "&amp;lt;!--*.*?--&amp;gt;", string.Empty, RegexOptions.Compiled | RegexOptions.Multiline);
                content = content.Replace("&amp;lt;![CDATA[", "&amp;lt;![CDATA[" + Environment.NewLine);
                content = content.Replace("//]]&amp;gt;", Environment.NewLine + "//]]&amp;gt;");
                content = content.Replace("\t", " ");
                var i = 0;
                content = Regex.Replace(
                    content,
                    "&amp;lt;pre&amp;gt;.*&amp;lt;/pre&amp;gt;",
                    (match) =&amp;gt;
                        {
                            try
                            {
                                return matches[i].Value;
                            }
                            finally
                            {
                                i += 1;
                            }
                        },
                    RegexOptions.Singleline);
                foreach (var match in matches)
                {                    
                }
                return content;
            }

            #endregion
        }

        #endregion
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Web.Config Extension&lt;/h4&gt;
&lt;pre&gt;&lt;code class="xml"&gt;  &amp;lt;system.webServer&amp;gt;
    &amp;lt;modules runAllManagedModulesForAllRequests="false"&amp;gt;
      &amp;lt;remove name="CompressionModule" /&amp;gt;
      &amp;lt;add name="CompressionModule" type="ProCompressor.CompressionModule" /&amp;gt;
    &amp;lt;/modules&amp;gt;
&lt;/code&gt;&lt;/pre&gt;</description><pubDate>Thu, 08 Jan 2015 03:34:00 GMT</pubDate><guid isPermaLink="true">http://prosodev.com:80/net-blog/compression-of-html-output-module</guid><category>.NET</category><category>Asp.NET</category></item><item><title>Find all controls displayed on any control in Winforms</title><link>http://prosodev.com:80/net-blog/find-all-controls-displayed-on-any-control-in-winforms</link><description>&lt;h1&gt;Overview&lt;/h1&gt;
&lt;div class="blogoverview"&gt;Controls-Collection in Winforms-Controls will give you a list of all direct children. With a simple recursive function you will be able to find all controls available in control.&lt;/div&gt;
&lt;p&gt;Controls-Collection in Winforms-Controls will give you a list of all direct children. With a simple recursive function you will be able to find all controls available in control.&lt;/p&gt;
&lt;h1&gt;Snippet&lt;/h1&gt;
&lt;pre&gt;&lt;code class="csharp"&gt;	// helper class

    internal static class WinformsHelper
    {
        public static List&amp;lt;Control&amp;gt; FindAllControls(this Control control)
        {
            var result = new List&amp;lt;Control&amp;gt; {control};
            foreach (var ctrl in control.Controls.Cast&amp;lt;Control&amp;gt;()) result.AddRange(FindAllControls(ctrl));
            return result;
        }
	}
	
	....
	
	public class MyForm : Form
	{
		....
		public void FindControls()
		{
			var allControls = this.FindAllControls();
		}
	}	
&lt;/code&gt;&lt;/pre&gt;</description><pubDate>Thu, 08 Jan 2015 03:23:00 GMT</pubDate><guid isPermaLink="true">http://prosodev.com:80/net-blog/find-all-controls-displayed-on-any-control-in-winforms</guid><category>.NET</category><category>WinForms</category></item><item><title>Make a path and a file writeable to all users</title><link>http://prosodev.com:80/net-blog/make-a-path-and-a-file-writeable-to-all-users</link><description>&lt;h1&gt;Overview&lt;/h1&gt;
&lt;div class="blogoverview"&gt;If a application has privileged access to file system (e.g. application runs under administrator account) a directory or file can't be edited by a non privileged user any more. The following snippet will give the access to filesystem (newly generated files or directories) to any user in the system. The file or directory have to exist before snippet will work.&lt;/div&gt;
&lt;p&gt;If a application has privileged access to file system (e.g. application runs under administrator account) a directory or file can't be edited by a non privileged user any more. The following snippet will give the access to filesystem (newly generated files or directories) to any user in the system. The file or directory have to exist before snippet will work.&lt;/p&gt;
&lt;h1&gt;Snippet&lt;/h1&gt;
&lt;pre&gt;&lt;code class="csharp"&gt;        public static void DirectoryForAllUsers(string targetDirectory)
        {
            var info = new DirectoryInfo(targetDirectory);
            var allUsersSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            var security = info.GetAccessControl();
            security.AddAccessRule(new FileSystemAccessRule(allUsersSid, FileSystemRights.FullControl, AccessControlType.Allow));
            info.SetAccessControl(security);
        }
		
        public static void DirectoryForAllUsers(string targetDirectory)
        {
            var info = new DirectoryInfo(targetDirectory);
            var allUsersSid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            var security = info.GetAccessControl();
            security.AddAccessRule(new FileSystemAccessRule(allUsersSid, FileSystemRights.FullControl, AccessControlType.Allow));
            info.SetAccessControl(security);
        }		
&lt;/code&gt;&lt;/pre&gt;</description><pubDate>Thu, 08 Jan 2015 03:16:00 GMT</pubDate><guid isPermaLink="true">http://prosodev.com:80/net-blog/make-a-path-and-a-file-writeable-to-all-users</guid><category>.NET</category></item><item><title>Check if application is running under Windows Vista or higher</title><link>http://prosodev.com:80/net-blog/check-if-application-is-running-under-windows-vista-or-higher</link><description>&lt;h1&gt;Overview&lt;/h1&gt;
&lt;div class="blogoverview"&gt;If you are using ProRibbon or any other library which is related to Windows Vista a program should stop working with a messagebox. The following snippet can be used to fullfill that task.&lt;/div&gt;
&lt;p&gt;If you are using ProRibbon or any other library which is related to Windows Vista a program should stop working with a messagebox. The following snippet can be used to fullfill that task.&lt;/p&gt;
&lt;h1&gt;Snippet&lt;/h1&gt;
&lt;h3&gt;Vistahelper.cs&lt;/h3&gt;
&lt;pre&gt;&lt;code class="csharp"&gt;   using System;
    using System.Windows.Forms;

    public static class VistaHelper
    {
        #region Enums

        public enum CheckStartupExitCodes
        {
            Passed = 0,
            Failed = -501,
        }

        #endregion

        #region Public Methods and Operators

        public static CheckStartupExitCodes CheckStartupArgs(bool showMessageBox = true, bool enableVisualStyles = true)
        {
            if (IsWinVistaOrHigher()) return CheckStartupExitCodes.Passed;
            if (!showMessageBox) return CheckStartupExitCodes.Failed;
            if (enableVisualStyles)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
            }
            MessageBox.Show("To run application you have to use Windows Vista or higher.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return CheckStartupExitCodes.Failed;
        }

        #endregion

        #region Methods

        private static bool IsWinVistaOrHigher()
        {
            var os = Environment.OSVersion;
            return (os.Platform == PlatformID.Win32NT) &amp;amp;&amp;amp; (os.Version.Major &amp;gt;= 6);
        }

        #endregion
    }&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Program.cs&lt;/h3&gt;
&lt;pre&gt;&lt;code class="csharp"&gt;    internal static class Program
    {
        #region Methods

        [STAThread]
        private static void Main(params string[] args)
        {
            //SQLiteConnection.ClearAllPools();
            //SQLiteConnection.Shutdown(true, true);
            //GC.Collect();
            //GC.WaitForPendingFinalizers(); 

            if (VistaHelper.CheckStartupArgs() != VistaHelper.CheckStartupExitCodes.Passed) return;
            if (AdministratorHelper.CheckStartupArgs(args) != AdministratorHelper.CheckStartupExitCodes.Passed) return;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());
        }

        #endregion
    }
&lt;/code&gt;&lt;/pre&gt;</description><pubDate>Thu, 08 Jan 2015 03:10:00 GMT</pubDate><guid isPermaLink="true">http://prosodev.com:80/net-blog/check-if-application-is-running-under-windows-vista-or-higher</guid><category>.NET</category><category>Console</category></item></channel></rss>