using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.SqlClient; using System.Text; using System.Data; using System.Configuration; using System.Collections; public partial class Pre_Owned_customasp_uploadpic : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { Getalbumfilename(); } protected void Getalbumfilename() { //String rootPath = Server.MapPath("~"); DirectoryInfo dinfo = new DirectoryInfo(Server.MapPath(@"~\Pre-Owned\customasp\carpicture")); DirectoryInfo[] diArr = dinfo.GetDirectories(); foreach (DirectoryInfo file in diArr) { platenum.Items.Add(new ListItem(file.Name, file.Name)); } } protected void CopyFolder(object sender, EventArgs e) { Array.ForEach(Directory.GetFiles(Server.MapPath(@"~\Pre-Owned\customasp\carpicture\") + platenum.SelectedValue), File.Delete); string sourcePath = Server.MapPath(@"~\Pre-Owned\customasp\uploads"); string targetPath = Server.MapPath(@"~\Pre-Owned\customasp\carpicture\") + platenum.SelectedValue; if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } foreach (var srcPath in Directory.GetFiles(sourcePath)) { //Copy the file from sourcepath and place into mentioned target path, //Overwrite the file if same file is exist in target path File.Copy(srcPath, srcPath.Replace(sourcePath, targetPath), true); } StatusLabel.Text = "Upload status: File uploaded!"; } /* both of these fuction can be used but only for .Net framework 4.5 and above, the current kentico runs on 4.0 :(, soo sad. so we are using the ajaxuploader module - 20/09/2016 -failfailfail protected void UploadButton_Click(object sender, EventArgs e) { if (FileUploadControl.HasFile) { try { if (FileUploadControl.PostedFile.ContentType == "image/jpeg" || FileUploadControl.PostedFile.ContentType == "image/png") { if (FileUploadControl.PostedFile.ContentLength < 5120000) { //Array.ForEach(Directory.GetFiles(@"c:\inetpub\wwwroot\Bermaz_Portal\Pre-Owned\customasp\carpicture\" + platenum.SelectedValue), File.Delete); Array.ForEach(Directory.GetFiles(Server.MapPath(@"~\Pre-Owned\customasp\carpicture\") + platenum.SelectedValue), File.Delete); string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/Pre-Owned/customasp/carpicture/" + platenum.SelectedValue + "/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } else { StatusLabel.Text = "Upload status: The file has to be less than 4MB!"; } } else { StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } } catch (Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } } protected void UploadMultipleFiles(object sender, EventArgs e) { foreach (HttpPostedFile postedFile in FileUploadControl.PostedFiles) { string filename = Path.GetFileName(postedFile.FileName); postedFile.SaveAs(Server.MapPath("~/Pre-Owned/customasp/carpicture/" + platenum.SelectedValue + "/") + filename); } StatusLabel.Text = string.Format("{0} files have been uploaded successfully.", FileUploadControl.PostedFiles.Count); } */ }