Hi,
oe folder gpf inside Edn ,Af,Pol like folder ,iside folder same no multiple pdf doc like Gpf/Af/Af_10008_pw.pdf,Af_10008_as.pdf,
Af_10008_df.pdf like multpile files ased and Categery And gpf no Serch get path and update related columns like Af_10008 i pass input how can i get all this 3 documents path in for loop C#

Abhishek YadavRank #217 · 11.3K reputationPosted Sep 25, 2024, 1:18 AM EDT
To retrieve file paths from a folder structure in C# based on the provided category (like
Af_10008), you can use theSystem.IOnamespace to search through the folders and gather the paths of matching files. Below is an example demonstrating how to do this in a C# Windows Forms application.Example Code
This example will search through the specified folder structure (
GpfcontainingAf,Pol, etc.) and retrieve the paths of files matching a specific prefix.using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; namespace DocumentFinderApp { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void SearchDocuments(string baseDirectory, string category) { // Create a list to hold the file paths List filePaths = new List(); // Get all directories inside the base directory string[] subDirectories = Directory.GetDirectories(baseDirectory); foreach (string dir in subDirectories) { // Search for PDF files that match the category string searchPattern = $"{category}*.pdf"; // E.g., Af_10008*.pdf string[] files = Directory.GetFiles(dir, searchPattern); // Add found files to the list filePaths.AddRange(files); } // Display the found file paths (or update your data source) DisplayFilePaths(filePaths); } private void DisplayFilePaths(List filePaths) { foreach (var path in filePaths) { // Example: Display in a message box or a list control MessageBox.Show(path); } } private void SearchButton_Click(object sender, EventArgs e) { // Example usage string baseDirectory = @"C:\Path\To\Gpf"; // Update to your base directory string category = "Af_10008"; // Example category input SearchDocuments(baseDirectory, category); } } }Explanation
SearchDocuments Method:
Af_10008*.pdf).DisplayFilePaths Method:
SearchButton_Click Event:
SearchDocumentsmethod with the specified base directory and category when a button is clicked.Additional Considerations
Thulasiram pakalaRank #1,834 · 808 reputationPosted Sep 25, 2024, 1:23 AM EDT
$"{category}*.pdf"; this in 2017 version only no isuue but older web site this code showing error
string pattern = $"{identifier}_*.pdf";
string pattern1 = $"{identifier}_*.pdf";
string Gpfno = gpfno;
string[] laststrings = Directory.GetFiles(directoryPath, pattern1);
string[] files = Directory.GetFiles(directoryPath, pattern);
i am using this code this one working latest version but web site s its showing error
i try "${" +identifier+"}" "_*.pdf like also but this code not working any other way in this string pattern1 = $"{identifier}_*.pdf"; in websites
Thulasiram pakalaRank #1,834 · 808 reputationPosted Sep 25, 2024, 1:26 AM EDT
string pattern = $"{identifier}_*.pdf"; $ { this is not working website 2010 version please any other wayin this string code
string pattern = $"{identifier}_*.pdf"