Thursday, January 23, 2014

Action Filters in MVC

 1)OutputCache  Filters in MVC:

Controler:

[OutputCache(Duration = 10)]
        public ActionResult test()
        {
            ViewBag.Date = DateTime.Now.ToString("T");
           
            return View();
        }

View:
@{
    ViewBag.Title = "test";
    @ViewBag.Date;
}

test

Monday, January 13, 2014

What is An ActionFilters in MVC..?

Sometimes you want to perform logic either before an action method is called or after an action method runs. To support this, ASP.NET MVC provides filters. Filters are custom classes that provide both a declarative and programmatic means to add pre-action and post-action behavior to controller action methods.



ASP.NET MVC supports the following types of action filters:
What are the Types of Action Filters ?


Types of Action Filters

  • Authorization filters. These implement IAuthorizationFilter and make security decisions about whether to execute an action method, such as performing authentication or validating properties of the request. The AuthorizeAttribute class and the RequireHttpsAttribute class are examples of an authorization filter. Authorization filters run before any other filter.
  •  

How to Create a Custom Action Filter for MVC 3 ?

http://sampathloku.blogspot.in/2013/03/how-to-create-custom-action-filter-for.html

Tuesday, September 17, 2013

modal popup using jquery in mvc3



            $("#btnsal").click(function () {
                debugger;
                var productid = '1';

                var url = '@Url.Action("Partialdata", "Cart")';
                $.post(url, { id: productid }, function (data) {
                    if (data != null) {
//                        $("#DivPrice").html(data);
//                        $("#DivPrice").show();

                        $('#DivPrice').dialog({
                            height: '500',

                            width: '400',
                            title: 'Dialod Demo',
                            modal: true,
                            resizable: false,
                            position: ['Top', 500]
                        }).html(data);
                    }
                    else {
                        $("#DivPrice").hide();
                    }

                });

            });
       

Friday, August 16, 2013

How To Move Directory To New location

How To Move Directory To New location

class Program
{
    static void Main(string[] args)
    {
        string sourcedirectory = @"C:\source";
        string destinationdirectory = @"C:\destination";
        string backupdirectory = @"C:\Backup";
        try
        {
            if (Directory.Exists(sourcedirectory))
            {
                if (Directory.Exists(destinationdirectory))
                {
                    //Directory.Delete(destinationdirectory);
                    Directory.Move(destinationdirectory, backupdirectory + DateTime.Now.ToString("_MMMdd_yyyy_HHmmss"));
                    Directory.Move(sourcedirectory, destinationdirectory);
                }
                else
                {
                    Directory.Move(sourcedirectory, destinationdirectory);
                }
            }

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        Console.ReadLine();
    }
}

Wednesday, August 14, 2013

How to Get Pdf File Page Count



How to Get Pdf File Page Count 

   public static int GetNoOfPagesPDF(string FileName)
        {

            int result = 0;

            string path="D:\\A\\PdfReader\\PdfReader\\Pdf\\EHRTest.pdf";
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            //FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read,);

            StreamReader r = new StreamReader(fs);

            string pdfText = r.ReadToEnd();



            System.Text.RegularExpressions.Regex regx = new Regex(@"/Type\s*/Page[^s]");

            System.Text.RegularExpressions.MatchCollection matches = regx.Matches(pdfText);

            result = matches.Count;

            return result;



        }

Tuesday, August 13, 2013

how to copy a directory in c#

how to copy a directory it contains .pdf files in c#

 protected void Button1_Click(object sender, EventArgs e)
        {
            string sourceDirectory = @"D:\pdf";
            string targetDirectory = @"D:\CopyFolderNew123";

            Copy(sourceDirectory, targetDirectory);
        }

        public static void Copy(string sourceDirectory, string targetDirectory)
        {
            DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
            DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);

            CopyAll(diSource, diTarget);
        }

        public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
        {
           // string sourceDirectory = @"D:\pdf";
         
            // Check if the target directory exists, if not, create it.
            if (Directory.Exists(target.FullName) == false)
            {
                Directory.CreateDirectory(target.FullName);
            }


          
            // Copy each file into it's new directory.
            foreach (FileInfo fi in source.GetFiles())
            {
                if (fi.Extension.ToUpper() == ".PDF")
                {
                    Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
                    fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
                }
               
            }

            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
            {

                DirectoryInfo nextTargetSubDir =target.CreateSubdirectory(diSourceSubDir.Name);
                CopyAll(diSourceSubDir, nextTargetSubDir);
              
            }

          
        }