Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<pre lang="xml"><%@ 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 align="center">
            <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>
                        <td><asp:Label ID="lbl" runat="server"></asp:Label></td>
            </tr>
            <tr>

                <td><asp:HyperLink ID="hyperlink2" Text="Sql commands n joins " runat="server" NavigateUrl="~/Sql commands n joins.docx"></asp:HyperLink></td>
                <td></td>
                <td></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 bUpload = Upload();
        //if (bUpload.Length>0)
        //{
        //    lbldisplay.Text="Uploaded Successfully";
        //}
        //else
        //{
        //    lbldisplay.Text = "Failed";
        //}
        string SUrl = DisplayUrl();
        if (SUrl.Length == 0)
        {
            lbl.Text="Error";
        }
        else
        {
            lbl.Text = "Successfully displayed Url address";
        }
    }

    public string Upload()
    {
        string FilePath = "";
        string[] a = new string[1];
        string FileName = "";
        if (filupload1.FileName.Length > 0)
        {
            FileName = filupload1.FileName;
            FilePath = Server.MapPath(@"~\");
            try
            {
                filupload1.SaveAs(FilePath + @"\" + FileName);
                //return FilePath;
                lbldisplay.Text = "successfully submitted";
            }
            catch
            {
                File.Delete(FilePath + @"\" + FileName);
                filupload1.SaveAs(FilePath + @"\" + FileName);

            }
                   //fullName = FilePath + @"\" + FileName;
           // lbldisplay.Text = "Uploaded successfully";

        }
        return string.Empty;
    }
    public string DisplayUrl()
    {
        try
        {
            string pageUrl = Request.Url.AbsoluteUri;
           // string pageUrl = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/");
            Response.Write(pageUrl);
            return pageUrl;
        }
        catch (Exception ex)
        {
            return string.Empty;
        }
    }
}
Posted
Comments
Yuri Vital 15-Jul-11 6:38am    
what is your problem ? If you want a answer elaborate a question !
[no name] 15-Jul-11 6:38am    
What is your question?
SruthiGeejula 15-Jul-11 6:58am    
i want url address with selected file i.e whatever i select a file.
ex:http://localhost:9518/FileUpload/Default.aspx
in default.aspx i want selected file
i.e http://localhost:9518/FileUpload/file.txt
how to get this?

1 solution

 
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