protected void ButtonSearch_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(@"Data Source=(localdb)\ProjectsV13;Initial Catalog=FudeyVillaDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"); SqlDataAdapter sda = new SqlDataAdapter("Select * from Recipes where (RCategory like '%" + TextBoxSearch.Text + "%') or (RName like '%" + TextBoxSearch.Text + "%') order by RName asc", con); DataTable dt = new DataTable(); sda.Fill(dt); DataListContent.DataSourceID = null; DataListContent.DataSource = dt; DataListContent.DataBind(); }
private void GenerateDownloadLinks() { string path = Server.MapPath("~/forms/" + Session["selectedCustomer"].ToString() + "/"); if (Directory.Exists(path)) { DataTable ShowContent = new DataTable(); ShowContent.Columns.Add("Icon", typeof(string)); ShowContent.Columns.Add("DownloadLink", typeof(string)); ShowContent.Columns.Add("FileName", typeof(string)); DirectoryInfo di = new DirectoryInfo(path); foreach (FileInfo fi in di.GetFiles()) { DataRow dr = ShowContent.NewRow(); dr["FileName"] = fi.Name; dr["DownloadLink"] = Server.MapPath("~/forms/" + Session["selectedCustomer"].ToString() + "/") + fi.Name; string ext = Path.GetExtension(fi.FullName); switch (ext) { case "pdf": dr["Icon"] = ResolveUrl("~/images/PdfIcon.png"); break; case "doc": dr["Icon"] = ResolveUrl("~/images/DocIcon.png"); break; case "xls": dr["Icon"] = ResolveUrl("~/images/ExcelIcon.png"); break; case "txt": dr["Icon"] = ResolveUrl("~/images/TxtIcon.png"); break; case "zip": dr["Icon"] = ResolveUrl("~/images/ZipIcon.png"); break; } ShowContent.Rows.Add(dr); } DataListContent.DataSource = ShowContent; DataListContent.DataBind(); } }
protected void btnImageupload_Click(object sender, EventArgs e) { string fileName; string filePath; string folder; folder = Server.MapPath("~/forms/" + Session["selectedCustomer"].ToString() + "/"); //retrieve name of posted file fileName = oFile.PostedFile.FileName; fileName = Path.GetFileName(fileName); if (oFile.Value != "") { //create folderz if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } //save to server filePath = folder + fileName; if (File.Exists(filePath)) { lblResult.Text = fileName + " file already exists in the database!"; lblResult.ForeColor = System.Drawing.Color.Red; } else { oFile.PostedFile.SaveAs(filePath); lblResult.Text = fileName + " has been successfully uploaded!"; lblResult.ForeColor = System.Drawing.Color.Green; } } else { lblResult.Text = "Click 'Browse' to select the file to upload."; } //displayyyyyyyyyy panelConfirm.Visible = true; DataListContent.DataBind(); }
private void GenerateDownloadLinks() { List <FileClass> lstFiles = new List <FileClass>(); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/"); if (Directory.Exists(path)) { DirectoryInfo di = new DirectoryInfo(path); foreach (FileInfo fi in di.GetFiles()) { lstFiles.Add(new FileClass() { FileName = fi.Name, DownloadLink = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data/" + fi.Name) }); } DataListContent.DataSource = lstFiles; DataListContent.DataBind(); } }