Hi, I heve nopcommerce 1.2 and i want to update to 2.4, but the only thing that i can't update is .cs file that i have in 1.2 that let me add a pdf or zip file to a product automaticly if i save it in a directory whit the same name as the product. If anyone can do it it will be great as I see a lot of people in this forum looking for a pdf in the product page.
This is the code of the file in 1.2:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.Common;
using NopSolutions.NopCommerce.Common.Audit;
using NopSolutions.NopCommerce.Common.Configuration.Settings;
using NopSolutions.NopCommerce.Common.Localization;
using NopSolutions.NopCommerce.Common.Media;
using NopSolutions.NopCommerce.Common.Orders;
using NopSolutions.NopCommerce.Common.Products;
using NopSolutions.NopCommerce.Common.Utils;
namespace NopSolutions.NopCommerce.Web.Modules
{
public partial class ProductFileDownload : System.Web.UI.UserControl
{
private string m_sCodProd = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
LoadFiles();
}
}
protected void BindData()
{
Product product = ProductManager.GetProductByID(ProductID);
if (product != null)
{
m_sCodProd = product.Name;
}
else
this.Visible = false;
}
protected void LoadFiles()
{
string m_sURL = URL();
string URLds = m_sURL + "DS_" + m_sCodProd + ".PDF";
string URLmn = m_sURL + "MN_" + m_sCodProd + ".PDF";
string URLzip = m_sURL + m_sCodProd + ".zip";
if (System.IO.File.Exists(URLds))
{
trDS.Visible = true;
}
else
{
trDS.Visible = false;
}
if (System.IO.File.Exists(URLmn))
{
trMN.Visible = true;
}
else
{
trMN.Visible = false;
}
if (System.IO.File.Exists(URLzip))
{
trDW.Visible = true;
}
else
{
trDW.Visible = false;
}
}
protected void DownloadFile(
string strFileURL,
string strFileName
)
{
try
{
System.Net.WebClient web = new System.Net.WebClient();
Byte[] buffer;
buffer = web.DownloadData(strFileURL + strFileName);
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("content-disposition", "attachment;filename=" + strFileName);
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
Response.Flush();
}
catch
{
}
}
protected void OpenPDF(string URL)
{
try
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.TransmitFile(URL);
Response.End();
}
catch
{
}
}
protected void lnkDS_Click(object sender, EventArgs e)
{
BindData();
string m_sURL = URL();
string URLds = m_sURL + "DS_" + m_sCodProd + ".PDF";
OpenPDF(URLds);
}
protected void lnkMN_Click(object sender, EventArgs e)
{
BindData();
string m_sURL = URL();
string URLmn = m_sURL + "MN_" + m_sCodProd + ".PDF";
OpenPDF(URLmn);
}
protected void lnkDw_Click(object sender, EventArgs e)
{
BindData();
string m_sURL = URL();
string Filezip = m_sCodProd + ".zip";
DownloadFile(m_sURL, Filezip);
}
public int ProductID
{
get
{
return CommonHelper.QueryStringInt("ProductID");
}
}
protected string URL()
{
string sURL = "";
System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
if (config.AppSettings.Settings.Count > 0)
{
KeyValueConfigurationElement element = config.AppSettings.Settings["DownloadFiles"];
if (element != null)
{
sURL = element.Value;
}
}
if (System.IO.Directory.Exists(sURL))
{
return sURL;
}
else
{
return Server.MapPath("/Download-Files/");
}
}
}
}