Monday, April 26, 2010

Deploying WCF Service in IIS : no svc MIME Type

I have started My First SilverLight application with WCF Service. When i want to deploy on IIS, i got this error saying no MIME type for this extension SVC not found. It is happening because this MIME type is not registered IIS.

Exception Details:

Server Error in Application “Default Web Site/MyFirstSLApp”
HTTP Error 404.3 – Not Found
Description: The page you are requesting cannot be served because of the Multipurpose Internet Mail Extensions (MIME) map policy that is configured on the Web server. The page you requested has a file name extension that is not recognized, and is not allowed.
Error Code: 0×80070032

I tried IIS MIME Types and I couldn’t found an application mapping for SVC file. After doing some goggling I found the fix.  You can resolve this using WCF Installation utility which comes with .Net Framework 3.0. Run the command prompt as Administrator, go to the Windows Communication Foundation folder in c:\Windows\Microsoft.NET\Framework\v3.0\ folder. Execute the servicemodelreg.exe with -i or /i switch.

wcf 

After the installation this try reloading the Page. It will fix this issue.

Wednesday, April 07, 2010

GridView Export from ASP.NET

Common method for Exporting gird content 

#region Methods : ExportGridView & PrepareControlForExport
    /// <summary>
    /// Purpose : To Export GridView in Excel format.
    /// </summary>
    /// <param name="strFileName">Execl File name</param>
    /// <param name="gv">Grid View</param>
    /// <param name="isRemove">If false, wont check the remove column</param>
    /// <param name="arrayList">List of columns to hide {1,2,3}</param>
    /// <param name="removeColumn">Column to remove</param>
    public void ExportGridView(string strFileName, GridView gv, bool isRemove, ArrayList arrayList)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader(
            "content-disposition", string.Format("attachment; filename={0}", strFileName));
        HttpContext.Current.Response.ContentType = "application/ms-excel";

        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);

        Table tableExport = new Table();
        // Setting line borders to the exported grid
        tableExport.GridLines = GridLines.Both;

        if (isRemove == false)
        {
            if (gv.HeaderRow != null)
            {
                this.PrepareControlForExport(gv.HeaderRow);
                tableExport.Rows.Add(gv.HeaderRow);
            }
            foreach (GridViewRow row in gv.Rows)
            {
                this.PrepareControlForExport(row);
                tableExport.Rows.Add(row);
            }
            if (gv.FooterRow != null)
            {
                this.PrepareControlForExport(gv.FooterRow);
                tableExport.Rows.Add(gv.FooterRow);
            }

        }
        else
        {
            if (arrayList.Count > 0)
            {
                    if (gv.HeaderRow != null)
                    {
                        this.PrepareControlForExport(gv.HeaderRow);
                        tableExport.Rows.Add(gv.HeaderRow);
                        for (int removeColumn = 0; removeColumn < arrayList.Count; removeColumn++)
                        {
                            gv.HeaderRow.Cells.Remove(gv.HeaderRow.Cells[Int32.Parse(arrayList[removeColumn].ToString())]);
                        }
                    }
                    foreach (GridViewRow row in gv.Rows)
                    {
                        this.PrepareControlForExport(row);
                        for (int removeColumn = 0; removeColumn < arrayList.Count; removeColumn++)
                        {
                            row.Cells.Remove(row.Cells[Int32.Parse(arrayList[removeColumn].ToString())]);
                        }
                        tableExport.Rows.Add(row);
                    }
                    if (gv.FooterRow != null)
                    {
                        this.PrepareControlForExport(gv.FooterRow);
                        tableExport.Rows.Add(gv.FooterRow);
                        for (int removeColumn = 0; removeColumn < arrayList.Count; removeColumn++)
                        {
                            gv.FooterRow.Cells.Remove(gv.FooterRow.Cells[Int32.Parse(arrayList[removeColumn].ToString())]);
                        }
                    }
            }
        }

        tableExport.RenderControl(htw);
        HttpContext.Current.Response.Write(sw.ToString().Trim());
        HttpContext.Current.Response.End();

    }

    /// <summary>
    /// Prepaing the control for export
    /// Customize your controls depening on your logic    ///
    /// </summary>
    /// <param name="control"></param>
    private void PrepareControlForExport(Control control)
    {
        for (int i = 0; i < control.Controls.Count; i++)
        {
            Control current = control.Controls[i];
            if (current is LinkButton)
            {
                control.Controls.Remove(current);
                if ((current as LinkButton).Style["display"] != "none" && (current as LinkButton).Visible)
                {
                    control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text.Trim()));
                }
            }
            else if (current is ImageButton)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText.Trim()));
            }
            else if (current is HyperLink)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text.Trim()));
            }
            else if (current is DropDownList)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text.Trim()));
            }
            else if (current is CheckBox)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
            }
            else if (current is HtmlAnchor)
            {
                control.Controls.Remove(current);
                control.Controls.AddAt(i, new LiteralControl((current as HtmlAnchor).InnerText.Trim()));
            }
            else if (current is Label)
            {
                control.Controls.Remove(current);
                if ((current as Label).Style["display"] != "none" && (current as Label).Visible)
                {
                    control.Controls.AddAt(i, new LiteralControl((current as Label).Text.Trim()));
                }
            }

            if (current.HasControls())
            {
                this.PrepareControlForExport(current);
            }
        }
    }
    #endregion Methods : ExportGridView & PrepareControlForExport

 

Sample code to call code behind

   ArrayList list = new ArrayList();
            DraftsGridView.AllowPaging = false;
            BindDrafts("StartDateTime", ASCENDING);
         // Add list of columns that are to be hidden. If you not need any columns
        //then just send list object without adding any and set the third parameter to false
            list.Add(3);
            common.ExportGridView("Drafts.xls", DraftsGridView, true, list);

Wednesday, March 17, 2010

Tips & Tricks: Run Command Shortcuts

Here are the few shortcuts that lot of people will love instead of browsing through control panel and all.

Accessibility Controls : access.cpl
Add Hardware Wizard : hdwwiz.cpl
Add/Remove Programs : appwiz.cpl
Administrative Tools 
Automatic Updates : wuaucpl.cpl
Bluetooth Transfer Wizard : fsquirt
Calculator : calc
Certificate Manager : certmgr.msc
Character Map : charmap
Check Disk Utility : chkdsk
Clipboard Viewer : clipbrd
Command Prompt : cmd
Component Services : dcomcnfg
Computer Management : compmgmt.msc
Date and Time Properties : timedate.cpl
DDE Shares : ddeshare
Device Manager : devmgmt.msc
Direct X Control Panel (If Installed)* : directx.cpl
Direct X Troubleshooter : dxdiag
Disk Cleanup Utility : cleanmgr
Disk Defragment : dfrg.msc
Disk Management : diskmgmt.msc
Disk Partition Manager : diskpart
Display Properties : control desktop
Display Properties : desk.cpl
Display Properties (w/Appearance Tab Preselected) :

Dr. Watson System Troubleshooting Utility : drwtsn32
Driver Verifier Utility : verifier
Event Viewer : eventvwr.msc
File Signature Verification Tool : sigverif
Findfast : findfast.cpl
Folders Properties : control folders
Fonts : control fonts
Fonts Folder : fonts
Free Cell Card Game : freecell
Game Controllers : joy.cpl
Group Policy Editor (XP Prof) : gpedit.msc
Hearts Card Game : mshearts
Iexpress Wizard : iexpress
Indexing Service : ciadv.msc
Internet Properties : inetcpl.cpl
IP Configuration (Display Connection Configuration) : ipconfig /all
IP Configuration (Display DNS Cache Contents) : ipconfig /displaydns
IP Configuration (Delete DNS Cache Contents) : ipconfig /flushdns
IP Configuration (Release All Connections) : ipconfig /release
IP Configuration (Renew All Connections) : ipconfig /renew
IP Configuration (Refreshes DHCP & Re-Registers DNS) : ipconfig /registerdns
IP Configuration (Display DHCP Class ID) : ipconfig /showclassid
IP Configuration (Modifies DHCP Class ID) : ipconfig /setclassid
Java Control Panel (If Installed) : jpicpl32.cpl
Java Control Panel (If Installed) : javaws
Keyboard Properties : control keyboard
Local Security Settings : secpol.msc
Local Users and Groups : lusrmgr.msc
Logs You Out Of Windows : logoff
Microsoft Chat : winchat
Minesweeper Game : winmine
Mouse Properties : control mouse
Mouse Properties : main.cpl
Network Connections : control netconnections
Network Connections : ncpa.cpl
Network Setup Wizard : netsetup.cpl
Notepad : notepad
Nview Desktop Manager (If Installed) : nvtuicpl.cpl
Object Packager : packager
ODBC Data Source Administrator : odbccp32.cpl
On Screen Keyboard : osk
Opens AC3 Filter (If Installed) : ac3filter.cpl
Password Properties : password.cpl
Performance Monitor : perfmon.msc
Phone and Modem Options : telephon.cpl
Power Configuration : powercfg.cpl
Printers and Faxes : control printers
Printers Folder : printers
Private Character Editor : eudcedit
Quicktime (If Installed) : QuickTime.cpl
Regional Settings : intl.cpl
Registry Editor : regedit
Registry Editor : regedit32
Remote Desktop : mstsc
Removable Storage : ntmsmgr.msc
Removable Storage Operator Requests : ntmsoprq.msc
Resultant Set of Policy (XP Prof) : rsop.msc
Scanners and Cameras : sticpl.cpl
Scheduled Tasks : control schedtasks
Security Center : wscui.cpl
Services : services.msc
Shared Folders : fsmgmt.msc
Shuts Down Windows : shutdown
Sounds and Audio : mmsys.cpl
Spider Solitare Card Game : spider
SQL Client Configuration : cliconfg
System Configuration Editor : sysedit
System Configuration Utility : msconfig
System File Checker Utility (Scan Immediately) : sfc /scannow
System File Checker Utility (Scan Once At Next Boot) : sfc /scanonce
System File Checker Utility (Scan On Every Boot) : sfc /scanboot
System File Checker Utility (Return to Default Setting) : sfc /revert
System File Checker Utility (Purge File Cache) : sfc /purgecache
System File Checker Utility (Set Cache Size to size x) : sfc /cachesize=x
System Properties : sysdm.cpl
Task Manager : taskmgr
Telnet Client : telnet
User Account Management : nusrmgr.cpl
Utility Manager : utilman
Windows Firewall : firewall.cpl
Windows Magnifier : magnify
Windows Management Infrastructure : wmimgmt.msc
Windows System Security Tool : syskey
Windows Update Launches : wupdmgr
Windows XP Tour Wizard : tourstart
Wordpad : write

Hope it helps you..