Click here to Skip to main content
15,917,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td><asp:Label id="lblselectfile" Text="Select File" runat="server"></asp:Label></td>
                <td><asp:FileUpload ID="filupload1"  runat="server" /></td>
            </tr>
            <tr>
                <td><asp:Button ID="btnsubmit" Text="Submit" runat="server"
                        onclick="btnsubmit_Click" /></td>
                        <td><asp:Label ID="lbldisplay" runat="server"></asp:Label></td>
            </tr>
            <tr>
                <td><asp:HyperLink ID="hyperlink1" Text="color" runat="server" NavigateUrl="~/Color.docx"></asp:HyperLink></td>
                <td><asp:HyperLink ID="hyperlink2" Text="Sql commands n joins " runat="server" NavigateUrl="~/Sql commands n joins.docx"></asp:HyperLink></td>
                <td><asp:HyperLink ID="hyperlink3" Text="3rd Transaction" NavigateUrl="~/3rd transaction.xlsx" runat="server"></asp:HyperLink></td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

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;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {

        string FilePath = "";
        string[] a = new string[1];
        string FileName = "";

        if (filupload1.FileName.Length > 0)
        {
            FileName = filupload1.FileName;
            FilePath = Server.MapPath(@"~\Files");
            try
            {
                filupload1.SaveAs(FilePath + @"\" + FileName);
            }
            catch { File.Delete(FilePath + @"\" + FileName);
            filupload1.SaveAs(FilePath + @"\" + FileName);
            }

            lbldisplay.Text = "Uploaded successfully";
            }
        }
    }
Posted
Updated 13-Jul-11 19:53pm
v2
Comments
walterhevedeich 14-Jul-11 1:54am    
What problems are you having with this code? You need to be more specific for us to be able to help you.
lovejeet0707 14-Jul-11 2:53am    
Be More Specific to help you.

1 solution

I gave u some solution. Convert the filename to string using ToString() method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900