Sunday, November 18, 2012

Asp.net development server failed to start listening on port

Recently, I am working on Visual Studio 2010. It was working fine but one morning i get a message 

"Asp.net development server failed to start listening on port 1478.
Error Message: only one usage of each socket address is normally permitted ."


Go to the Solution Explorer in Visual Studio --> then click on the web site application--> press F4 or go application’s property window.  set "Use Dynamic Port" to "False". Also set the port number instead of previous port number.

Happy Programing :)

Thursday, November 15, 2012

New features in ASP.NET 4.0 and Visual Studio 2010

Code Snippets:
Code snippets are pre-developed code templates which can save time spent on thinking about the syntax. VS2010 are introduced for JScript, HTML, and ASP.NET markup as well.
Press CTRL+K, CTRL+X.
Inside the script tag, it would be

And inside the HTML:


Generate From Usage

In previous versions of ASP.NET, Microsoft introduced code refactoring to generate methods and identifiers from existing code. In ASP.NET 4.0, there is a new concept of Generate From Usage - generates properties, methods, classes, and other types based on existing code.
Write some code, select it and right click on the left most character, and you will get options to change it to a property or method etc. This option is shown only if you do not define an identifier. For example, in the following example intellisense, it will not show the options to extract a property if you right click on the variable i.

Tuesday, November 13, 2012

How to embed video file into asp.net?

This article demonstrates how to play an swf file (flash) in asp.net. I have used flash file & .wmv file to play in asp.net website.
For Flash file:
Put this code in your aspx file.












For wmv file:

                
                
                
                
                
                
                
                
                
                
                
                
            
Also change this line: give your file path
 

Happy Codding :)

Monday, October 15, 2012

Download file using linq from the GridView asp.net 4.0

I am going to tell how to download files using a gridview in asp.net. I have used C# as my language.
In .aspx page:

                        
                        
                            
                                
                                    
                                
                            
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        


Bind GridView using Linq:
private void BindGridDownloadFile()
        {
         CIPEntities _context = new CIPEntities();
            _context = new CIPEntities();
            List SpritsData = new List();
            SpritsData = _context.tbl_SpiritsSyndicateData.Where(c => c.CategoryId == 1).ToList();
            GridView1.DataSource = SpritsData;
            GridView1.DataBind();
        }
Define the event "GridView1_RowCommand" as follows:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "OpenFile")
            {

                string name = (string)e.CommandArgument;
                string fullFilePath = Server.MapPath("~/Content/Upload/" + name); //might be you need to change this statement if file does not exist within application folders

                System.IO.FileInfo fileInfo = new System.IO.FileInfo(fullFilePath);
                if (fileInfo.Exists)
                {
                    this.Response.Clear();

                    this.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
                    this.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                    this.Response.ContentType = "application/octet-stream";
                    //this.Response.TransmitFile(fileInfo.FullName);
                    this.Response.BinaryWrite(File.ReadAllBytes(fileInfo.FullName));
                    this.Response.End();
                }
                else
                {
                    Response.Write("NO FILE PRESENT");
                }
            }

        }

If need project code then feel free email me please.
I hope you like this article. Enjoy!

Filtering RSS Feed using LINQ & Binding ASP.NET ListView

In this article, I would like to demonstrate how we can parse RSS feeds & filtering from website and display on asp.net ListView.
ASP.Net Namespaces :C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.ServiceModel.Syndication;
using System.Xml.Linq;
using System.Linq.Expressions;
using System.Xml;
GetRSS Function: The GetRSS function is responsible to pull the RSS feed & filtering and display it on the web page.
Refer the code below C#
private void GetRSS()
{
string Subcategory = "Winne"; // searching keyword
string rssUri = "http://www.just-drinks.com/mhusa/rssdata.aspx?feed=wine";//Your RSS Url
var doc = System.Xml.Linq.XDocument.Load(rssUri);
var rssFeed = from el in doc.Elements("rss").Elements("channel").Elements("item")
              where el.Element("title").Value.ToLowerInvariant().Contains(Subcategory.ToLowerInvariant()                ||el.Element("description").Value.ToLowerInvariant().Contains(Subcategory.ToLowerInvariant())
             select new
             {
                 Title = el.Element("title").Value,
                  Link = el.Element("link").Value,
                  Description = el.Element("description").Value
              };

lvFeed1.DataSource = filterrssFeed;// Listview
lvFeed1.DataBind();}
Display the retrieved RSS Feeds To display the data I am using ASP.Net list view Control Refer below:





  • ” style=”color: Black;text-decoration: none; font-size: small”> <%#Eval(“Title”) %>
  • I hope you like this article. Enjoy!

    Sunday, October 14, 2012

    Solve: HTTP Error 500.23 – Internal Server Error

    If you website shows the following error:

    HTTP Error 500.23 – Internal Server Error

    An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

    Please refer to the following steps to resolve the issue:

    In your web.config make sure these keys exist:
    
    
    
    
    
    

    Hope this helps!!!

    Error: allowDefinition=’MachineToApplication’ beyond application level

    You can solve this bellow way :

    # clean & then rebuild.

    # just close VS and open again.

    # the downloaded project may be inside another sub folder… open the folder which has you .net files.
    c:/CFC1/CFC/ (all files)

    You have to open CFC folder from vs… not CFC1.

     Hope this will be help you!!

    MVC RedirectToAction with parameter

    Easily you can Pass the edit as part of the routeValues parameter of the RedirectToAction() method
    return RedirectToAction("ActionName", new { edit = false });
    
    Happy Programming!!

    The object cannot be attached because it is already in the object context.

    I have solved this error .If the object is already attached, simply put EntityState to Unchanged. Namespaces :C#
    using System.Data
    C#
    _context.ObjectStateManager.ChangeObjectState(requisitionEdit, EntityState.Unchanged);
    _context.Attach(requisitionEdit);
    _context.ObjectStateManager.ChangeObjectState(requisitionEdit, EntityState.Modified);
    
    If have any query then feel free ask me

    How to get the domain name and username?

    This article shows How to get the Windows current logged user name using ASP.NET. Namespaces :C#
    using System.Security.Principal;
    
    Find_Domain_User()Function
    The Find_Domain_User() function is use to get domain username & domain name. Refer the code below C#
    public static string Find_Domain_User()
    {
    string the_user = WindowsIdentity.GetCurrent().Name;
    if (the_user != null || the_user != “”)
    {
    string username = “”, domain_name = “”;
    int boundary = the_user.IndexOf(“\\”);
    domain_name = the_user.Substring(0, boundary);
    username = the_user.Substring(boundary + 1, the_user.Length – boundary – 1);
    return username;
    }
    return null;
    }
    
    Hope this will help you !!!

    How to Read & Display Rss feed in asp.net website ?


    In this article I am explaining how to read RSS feeds from website and display it on my Website using ASP.Net Namespaces :C#
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;
    using System.ServiceModel.Syndication;
    using System.Xml.Linq;
    using System.Linq.Expressions;
    using System.Xml;
    
    GetRSS Function The GetRSS function is responsible to pull the RSS feed and display it on the web page. Refer the code below C#
    private void GetRSS()
    {
    string rssUri = “http://www.just-drinks.com/mhusa/rssdata.aspx?feed=wine”;
    var doc = System.Xml.Linq.XDocument.Load(rssUri);
    var rssFeed = (from el in doc.Elements(“rss”).Elements(“channel”).Elements(“item”)
    select new
    {
    Title = el.Element(“title”).Value,
    Link = el.Element(“link”).Value,
    Description = el.Element(“description”).Value
    }).Take(20); // Take first 20 RSS Feed
    lvFeed1.DataSource = rssFeed;
    lvFeed1.DataBind();
    }
    
    Display the retrieved RSS Feeds To display the data I am using ASP.Net list view Control Refer below:
    
    
    
    
    
    
  • ” style=”color: Black;text-decoration: none; font-size: small”> <%#Eval(“Title”) %>
  • ” style=”text-decoration: none; color: Black”> <%#Eval(“Title”) %>
  • Good Day!!!!

    Dynamically show/hide gridview footer?


    This article explains how to show/hide  GridView Footer row. Just put this in page load or RowDataBound  event.

    GridView1.ShowFooter = false;

    If not work then put this code.
    GridView1.FooterRow.Visible = false;

    what is is the difference between GridView1.ShowFooter = false; and GridView1.FooterRow.Visible = false;
    Answer:
    FooterRow is represents the footer row in a GridView control.
    ShowFooter property is Gets or sets a value indicating whether the footer row is displayed in a GridView control.
    Happy Programming!!!!

    How to hide Gridview column ?

    This article demonstrates how to give users the ability to show or hide GridView columns as they require. This can be useful if there are some columns in a GridView which are not always required by all users. Just put this code in RowDataBound event.


    if (GridView1.Columns.Count > 0)
    GridView1.Columns[0].Visible = false; // for autogenerated columns
    GridView1.Columns[3].Visible = false;// for fourth column 
    
    

    Hope this will help you !!!

    Preventing Duplicate Record Insertion on Page Refresh — asp.net gridview


    ASP.NET Gridview:
    One of most common issue which many of the web developers face in their asp.net gridview applications, is that the duplicate records are inserted to the Database on page refresh.
    working on asp.net C# ….Under button click event i want to save something it’s work fine ….but after press the refresh button of browser then duplicate value insert ,how can stop this event….
    Solve:
    just adding the following code :

    System.Web.HttpContext.Current.Response.Redirect(Request.RawUrl);

    in the bottom of your insert method.

    I think your problem will be solve  :)