=========================== Upload Code ============================
String strFileName = "", strFileExtension, strSavedFilePath;
if (FileUploadCtd.HasFile)
{
strFileName = FileUploadCtd.FileName;
strFileExtension = strFileName.Substring(strFileName.LastIndexOf('.') + 1);
//if (strFileExtension.ToUpper() != "XLS")
//{
// ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('Select Excel File Only.')</script>");
// return;
//}
strSavedFilePath = Server.MapPath("../CTD_Files");
if (!Directory.Exists(strSavedFilePath))
{
Directory.CreateDirectory(strSavedFilePath);
}
strFileName = strFileName.Substring(0, strFileName.LastIndexOf('.')) + DateTime.Now.ToString("ddMMyyyyhhmmss") + "." + strFileExtension.Trim();
//strSavedFilePath += "\\" + strFileName.Substring(0, strFileName.LastIndexOf('.')) + DateTime.Now.ToString("ddMMyyyyhhmmss") + "." + strFileExtension.Trim();
strSavedFilePath += "\\" + strFileName;
FileUploadCtd.PostedFile.SaveAs(strSavedFilePath);
objDesign._strvCTDPath = strFileName; // save in DB table.
lblCTDLink.Text = strFileName;
}
else
{
objDesign._strvCTDPath = "";
lblCTDLink.Text = "";
}
// CTD file uploading end Here
===============================================================
=========================On Page Load (Data Load) ====================
// get file name from Db
lblCTDLink.Text = dtItemData.Rows[0]["vCTDPath"].ToString();
================================================================
======================= On download link button click ====================
protected void linkCTD_Click(object sender, EventArgs e)
{
// code for show donload link
if (lblCTDLink.Text.Trim() != "")
{
string strSavedFilePath;
strSavedFilePath = Server.MapPath("../CTD_Files" + "\\" + lblCTDLink.Text);
FileInfo fileInfo = new FileInfo(strSavedFilePath);
if (fileInfo.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);
}
}
else
{
objFnLib.WebMessageBox("No CTD Path Present", this);
}
}
================================================================
Subscribe to:
Post Comments (Atom)
-
Remarks This property specifies the appearance of the embedded Windows Media Player. When uiMode is set to "none", "mini...
-
<body> <form id="form1" runat="server"> <img class="RibbonL" src="Imag...
-
Partial Class Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Lo...
What is the use of n-tier architecture and 3-tier architecture?
how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...
No comments:
Post a Comment