<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>
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; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)