Saturday 31 August 2013

Download interrupted in IE10


In IE 10 you guys may get error Download interrupted error for some files which is grater then 20mb.

It's error occurred in IE10 only.

So For that you need to change something in your code.

If you use Response.close(); then remove it.

Just wirte something below.

Response.Flush();
Response.End();

For more info visit
http://blogs.msdn.com/b/ieinternals/archive/2012/07/16/content-length-and-transfer-encoding-validation-in-ie10-download-manager-couldnt-be-downloaded-retry-cancel.aspx

Tuesday 22 January 2013

Set Wallpaper using C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32;  

namespace CustomWallpaper
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14;
        private static readonly UInt32 SPIF_UPDATEINIFILE = 0x01;
        private static readonly UInt32 SPIF_SENDWININICHANGE = 0x02;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern Int32 SystemParametersInfo(
            UInt32 action, UInt32 uParam, String vParam, UInt32 winIni);

        private void Form1_Load(object sender, EventArgs e)
        {
            string strPath = "D:\\Projects\\Wallpaper\\Wallpaper.jpg";

            
            if (File.Exists(strPath))
            {
                SetWallpaper(strPath);
            }
            else
            {
                 strPath = "D:\\Projects\\Wallpaper\\Wallpaper.jpeg";
                if (File.Exists(strPath))
                { 
                    SetWallpaper(strPath); 
                }
                else
                {
                    strPath = "D:\\Projects\\Wallpaper\\Wallpaper.png";
                    if (File.Exists(strPath))
                    {
                        SetWallpaper(strPath); 
                    }
                    else
                    {
                        MessageBox.Show("Wallpaper.jpg Or Wallpaper.jpeg OR Wallpaper.png is not found on this path D:\\Projects\\Wallpaper\\");
                        this.Close();
                    }
                }
            }
        }

        private void SetWallpaper(string path)
        {
            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path,SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);

            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);            
            key.SetValue(@"WallpaperStyle", 2.ToString());
            key.SetValue(@"TileWallpaper", 0.ToString());            
            this.Close();
        }
    }
}


Monday 7 January 2013

Dialog is not a function in asp.net mvc

Guys you may get error when using jquery dialog function in your mvc application.It's because by default visual studio importing script which is old version script and also it's not importing jquery-ui-1.9.2.custom.js.

Dialog is function of ui js.

Here below you can see how js import by default in _layout.cshtml by visual studio. 




you have to change this and cut it and paste to top of the page because if you import jquery ui in top of the page then you may get the error that jquery is undefined. so as we are doing always put it to top of the page like as shown in below image. 



Now you guys have to update the version of js like below.



Now finally you guys have to update all new css version of ui inContent -->themes-->base

 

Wednesday 2 January 2013

Cascading dropdownlist using Jquery in MVC

Hii guys it's little difficult to do code for cascading dropdwon in asp.net mvc. In asp.net web forms We have a directly event of asp.net control. While in mvc we have html control and there is no event. So What we have to do we have to use Jquery event for this and make ajax call to our server side code and then bind the dropdown. Here below explain how to achieve this. First of all we have to import jquery so we can use jquery functions like we importing namespace in our C# code.

Here below is Jquery functions required to bind the dropdown list. Let me explain how these functions are working.
$('#Country').change this is jquery dropdown change event whatever code you write inside this it will run when country dropdown index is changed. Inside this event i am calling function GetState($(this).val())
In Getstate function i am calling one ajax method and calling action result "GetState" which is my C# code is written in controller named nik.
As you can see in action result i have argument name countryid so i can pass from here like this way data: { 'Countryid': Countryid }
Now with this country id i will return states in json format of the passed coutryid.
I also get city of selected state same way here is change event for state dropdwon $('#State').change


Here below is code you can see is that simple html code. But something strange you can find like VIEWBAG. View bag helps to maintain data when you move from controller to view. So here using view bag i am binding country dropdown. You can see in action result DropDown i am setting value of ViewBag. ViewBag.Country = items;
<%-- Here is dropdowns --%>
@{
    ViewBag.Title = "DropDown";
}

DropDown

Country : @Html.DropDownList("Country", (IEnumerable)ViewBag.Country, htmlAttributes: new { id = "Country"})
State :
City :

Here below you guys can see it is controller code. There are 3 different action result Dropdown,GetState,GetCity.
Let me explain when these all will fired.
1.Dropdwon :- This will fire when my page is load first time or when page is postback again.
2.GetState :- As i explain above it will fired by ajax method which i write in GetState(Countryid) jquery function.
3.GetCity :- Same as "GetState" it will fired by ajax method which i write in GetCity(Stateid) jquery function.
'Here is controller code

namespace MvcApplication1.Controllers
{
    public class NikController : Controller
    {
        public ActionResult DropDown()
        {       
            List items = new List();
                items.Add(new SelectListItem { Text = "---Select Country---", Value = "0", Selected = true });
                items.Add(new SelectListItem { Text = "India", Value = "1",Selected= true  });
                items.Add(new SelectListItem { Text = "USA", Value = "2" });
                items.Add(new SelectListItem { Text = "Russia", Value = "3"});
                items.Add(new SelectListItem { Text = "South Africa", Value = "4" });
                ViewBag.Country = items;            
                return View(); 
        }


        public ActionResult GetState(int Countryid)
        {
            List States = new List();

            if (Countryid==1)
            {
                States.Add(new SelectListItem { Text = "Gujarat", Value = "1", Selected = true });
                States.Add(new SelectListItem { Text = "Maharashtra", Value = "2"});
                States.Add(new SelectListItem { Text = "Rajsthan", Value = "3"});
                States.Add(new SelectListItem { Text = "Punjab", Value = "4"});
                States.Add(new SelectListItem { Text = "MP", Value = "5" });
                States.Add(new SelectListItem { Text = "Keral", Value = "6" });
                States.Add(new SelectListItem { Text = "Karnatak", Value = "7"});
                States.Add(new SelectListItem { Text = "Jammu", Value = "8"});
                States.Add(new SelectListItem { Text = "Assam", Value = "9"});
                States.Add(new SelectListItem { Text = "AP", Value = "10"});
            }                                                                                                    
            else if(Countryid ==2)
            {
                States.Add(new SelectListItem { Text = "Alabama", Value = "11", Selected = true });
                States.Add(new SelectListItem { Text = "Alaska", Value = "12"});
                States.Add(new SelectListItem { Text = "Arizona", Value = "13"});
                States.Add(new SelectListItem { Text = "Arkansas", Value = "14"});
                States.Add(new SelectListItem { Text = "California", Value = "15"});
                States.Add(new SelectListItem { Text = "Colorado", Value = "16"});
                States.Add(new SelectListItem { Text = "Connecticut", Value = "17"});
                States.Add(new SelectListItem { Text = "Delaware", Value = "18"});
                States.Add(new SelectListItem { Text = "Florida", Value = "19" });
                States.Add(new SelectListItem { Text = "Georgia", Value = "20"});
            }

            return Json(States);
        }


        public ActionResult GetCity(int Stateid)
        {
            List City = new List();

            if (Stateid == 1)
            {
       City.Add(new SelectListItem { Text = "Ahmedabad", Value = "1", Selected = true });
                City.Add(new SelectListItem { Text = "Surat", Value = "2" });
                City.Add(new SelectListItem { Text = "Baroda", Value = "3" });
                City.Add(new SelectListItem { Text = "Rajkot", Value = "4" });
                City.Add(new SelectListItem { Text = "Jamnagar", Value = "5" });
                City.Add(new SelectListItem { Text = "Junagadh", Value = "6" });
                City.Add(new SelectListItem { Text = "Jetpur", Value = "7" });
                City.Add(new SelectListItem { Text = "Bharuch", Value = "8" });
                City.Add(new SelectListItem { Text = "Limabi", Value = "9" });
                City.Add(new SelectListItem { Text = "Vapi", Value = "10" });
            }
            return Json(City);
        } 
    }
}
Here it is how it look likes.