Hello,
Can somebody guided me through on how to create a website to populate images by reading a text file when inserting data in a textboxes from website?
Thank you.
Hello,
Can somebody guided me through on how to create a website to populate images by reading a text file when inserting data in a textboxes from website?
Thank you.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manikandan MurugesanRank #300 · 8.4K reputationPosted Sep 21, 2024, 1:49 AM EDT
Glad that I'm able to help Ivonne and If the provided answer was working then kindly mark my answer as expected!
Manikandan MurugesanRank #300 · 8.4K reputationPosted Sep 17, 2024, 6:31 AM EDT
ID
Certainly! To create a website that displays images based on the content from a text file, and allows users to insert data into textboxes, you'll follow these general steps:
1. Design Your Website Layout
2. Set Up the Website Framework
3. Enable File Upload
4. Process the Text File
5. Update the Website Dynamically
imgtags) to display the images on your webpage. This is usually done with JavaScript or through server-side scripting if you are using a backend.6. Handle User Input
7. Test and Debug
8. Publish Your Website
Aman GuptaRank #193 · 12.4K reputationPosted Sep 18, 2024, 8:39 AM EDT
Hi Ivonne,
Yes, I can guide you through the process of creating a website that populates images by reading a text file while allowing users to insert data in textboxes. Here's a step-by-step approach using ASP.NET MVC, assuming you're familiar with .NET.
OverviewWe will create a simple ASP.NET MVC web application where:
- Users input data via textboxes on a form.
- The website reads a text file containing image paths or URLs.
- Based on the form input, relevant images will be displayed.
Steps:1. Set up the ASP.NET MVC Project
2. Create the Model
You’ll need a model to handle the data from the form. For example, you can create a
ProductModelclass with properties for the input fields and images.public class ProductModel { public string ProductName { get; set; } public string ProductDescription { get; set; } public List ImagePaths { get; set; } // To hold image paths }3. Create the Controller
The controller will handle user input and read from the text file.
public class ProductController : Controller { // GET: Product public ActionResult Index() { var model = new ProductModel(); return View(model); } [HttpPost] public ActionResult SubmitForm(ProductModel model) { // Read image paths from a text file string filePath = Server.MapPath("~/App_Data/ImagePaths.txt"); model.ImagePaths = System.IO.File.ReadAllLines(filePath).ToList(); // Return the populated model back to the view to display images return View("Index", model); } }4. Create the View
The view (
Index.cshtml) will include textboxes for user input and a section to display images.@model YourNamespace.Models.ProductModel Insert Product Details Product Name: Product Description: @if (Model != null && Model.ImagePaths != null && Model.ImagePaths.Any()) { Images: @foreach (var imagePath in Model.ImagePaths) { } }5. Text File with Image Paths
In your project, create a folder named App_Data. Inside it, create a text file called
ImagePaths.txt. Add image paths or URLs, one per line.Example
ImagePaths.txt:Make sure the images are stored in the appropriate folder (
~/images/in this case).6. Run the Application
- Press F5 to run the application.
- Enter product data into the textboxes and submit the form.
- The images from the text file will be displayed on the page.
Summary:SubmitFormaction in the controller reads the text file containing image paths.Index.cshtml) receives the paths and dynamically displays the images on the page.This example can be extended based on your specific needs, like storing form data in a database or allowing users to upload their own images.
Ivonne AspilcuetaRank #4,887 · 320 reputationPosted Sep 19, 2024, 5:22 PM EDT
Hello Manikandan Murugesan,
Do you know how many hours I was looking for that answer, I knew it was something on that line, but noone explain as clear as you just did. Thank you.
Ivonne AspilcuetaRank #4,887 · 320 reputationPosted Sep 19, 2024, 12:54 PM EDT
Hello,
This is so far what I did: but my onclick button is not working, I am trying to debug/test but it is not evenrunning when click on button.
public partial class Conversion : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { try { if (!FileUpload1.HasFile) //Validation { Response.Write("No file Selected"); return; } else { // Read and Extract Information from the Index.txt File: string path = ConfigurationManager.AppSettings["ImageBasePath"]; var files = Directory.GetFiles(path, "index.txt", SearchOption.AllDirectories); // Read and populate textboxes from Index.txt string filePath = Path.Combine(files); var lines = File.ReadAllLines(Path.Combine(filePath)); //var lines = File.ReadAllLines(filePath); foreach (var line in lines) { var parts = line.Split('|'); if (parts.Length >= 9) { // Extract required information string acctNumber = parts[0]; string chkNumber = parts[1]; string chkAmount = parts[2]; string imgDate = parts[5]; string imagePath = parts[8]; // Populate the textboxes acctNumber = txtacctNumber.ToString(); chkNumber = txtchkNumber.ToString(); chkAmount = txtchkAmount.ToString(); imgDate = txtimgDate.ToString(); //Store the imagePath if needed ViewState["ImagePath"] = imagePath; // break; // Remove this if you want to handle multiple lines } // Extract values from textboxes string acctNumbers = txtacctNumber.Value; string chkNumbers = txtchkNumber.Value; string chksAmount = txtchkAmount.Value; string imgDates = txtimgDate.Value; string imagePaths = ViewState["ImagePath"].ToString(); // Retrieve the base path from the configuration string basePath = ConfigurationManager.AppSettings["ImageBasePath"]; // Construct the full path to the image file string fullImagePath = Path.Combine(basePath, imagePaths); //Populate image on website { Response.Write("Image has been Added"); } } }Manikandan MurugesanRank #300 · 8.4K reputationPosted Sep 19, 2024, 1:24 PM EDT
Hi Ivonne,
The onclick event handler for the button is not functioning as expected because the button element is not correctly configured to work with server-side code in ASP.NET WebForms. In ASP.NET, buttons that need to trigger server-side events should be implemented using asp:Button or asp:LinkButton controls instead of regular HTML buttons.