Thursday, February 28, 2013

How find html tag and remove it from string in C#

     

How find html tag from string in C#
=========================

   Situation: i want to find and remove all the javascript from mystring. which can be like

<script  type="text/javascript" id="someid">

.......Some functions goes here

</script>

Now i want to remove all the script content from my string. The best way to remove script content is by using  Regularexpression

            Regex reg=new Regex("<script (.+?)</script>");
            reg.Replace(test, "");

Example:
======

 string test = "<script type='text/javascript'> Some functions goes here </script> A C# string is an array of characters declared using the string keyword. A string literal is declared using quotation marks, as shown in the following example:   ";
            test += " <br/> You can extract substrings, and concatenate strings, like this:";
            test += "<script> another text </script> <br /> String objects are immutable, meaning that they cannot be changed once they have been created. Methods that act on strings actually return new string objects. In the previous example, when the contents of s1 and s2 are concatenated to form a single string, the two strings containing \"orange\" and \"red\" are both unmodified. The += operator creates a new string that contains the combined contents. The result is that s1 now refers to a different string altogether. A string containing just \"orange\" still exists, but is no longer referenced when s1 is concatenated.";
            Regex reg=new Regex("<script (.+?)</script>");

            reg.Replace(test, "");

response.write(test);

Wednesday, February 27, 2013

How To Date filter with Devexpress XPO XPDataView



How To Date filter with Devexpress XPO XPDataView




 public string GetCreatedDate(string period, string column, string customFilterFrom = null, string CustomFilterTo = null)
        {

            string date = string.Empty; string filterexp = string.Empty;
            DateTime dt = DateTime.Today;
            switch (period.ToUpper())
            {

                case "CUSTOM":
                    date = new BetweenOperator(column, Convert.ToDateTime(customFilterFrom.Replace("/", "-")),       Convert.ToDateTime(CustomFilterTo.Replace("/", "-"))).ToString();

                    break;
                case "TODAY":
                    date = new BetweenOperator(column, dt, dt.AddDays(1)).ToString(); //string.Format("[{1}] = #{0}#", dt, column);//.ToString("MM/dd/yyyy")
                    break;
                case "LASTDAY":
                     date = new BetweenOperator(column,dt.AddDays(-1),dt).ToString();
                    break;
                case "THISYEAR":
                    date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, 4, 1), dt.AddDays(1)).ToString();
                    break;

                case "THISMONTH":
                    date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), dt.AddDays(1)).ToString();
                    break;
                case "LASTMONTH":
                    date = new BetweenOperator(column, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(-1), new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1)).ToString();
              
                    break;
                case "THISWEEK":
                    int days = (DateTime.Now.DayOfWeek - DayOfWeek.Sunday) - 1;
                    DateTime thisweek = DateTime.Now.AddDays(-(days));
                    date = new BetweenOperator(column, thisweek, thisweek.AddDays(days)).ToString();
                    break;
                case "LASTWEEK":
                    int diff = (DateTime.Now.DayOfWeek - DayOfWeek.Sunday) + 6;
                    DateTime mondayOfLastWeek = DateTime.Now.AddDays(-diff);
                    date = new BetweenOperator(column, mondayOfLastWeek, mondayOfLastWeek.AddDays(diff -6)).ToString();
                     break;
                default:
                    date = string.Format("[{0}] = '{1}'", column, period);
                    break;

            }
            return date;
        }



Refer my original post in devexpress : Unable to filter date values in xpo DataSource