1
votes

Comment ajouter des points de balle dans une page aspx lors de la lecture d'un fichier txt?

Ce que je veux faire, c'est lire un fichier à partir d'un fichier .txt et lorsque le texte du fichier .txt apparaît dans la zone de texte, il doit être formaté sous forme à puces (chaque ligne commence par un point) des lignes simples.

Voici comment je lis le fichier depuis le serveur:

protected void btn_Click(object sender, EventArgs e)    
{    
    string txt = File.ReadAllText(Server.MapPath("~/TextFile1.txt"));    
    txtBox1.Text = txt;    
} 


<html xmlns="http://www.w3.org/1999/xhtml">    
<head runat="server">    
</head>    
<body>    
    <form id="form1" runat="server">    
        <div>    
        <asp:button id="btn1" runat="server" text="Read" onclick="btn_Click" /><br /><br />    
            Results:<br />     
            <asp:TextBox ID="txtBox1" runat="server" TextMode="MultiLine" Height="250px" width="350px">    
            </asp:TextBox>    
            </div>    
    </form>     
</body>     
</html>    

 entrez la description de l'image ici


0 commentaires

3 Réponses :


0
votes

Il y a 2 façons d'y parvenir:

  1. Utilisez BulletedList à la place.
  2. Lisez ligne par ligne de votre fichier TextFile1.txt puis ajoutez le texte \ u2022 avant chaque ligne.

0 commentaires

0
votes

utilisez \ u2022

protected void btn_Click(object sender, EventArgs e)    
{ 
string[] txt  = File.ReadAllLines(Server.MapPath("~/TextFile1.txt")); 
foreach (string line in txt )
{
txtBox1.Text += "\u2022 '" + line + "'\t\n";
}
}


2 commentaires

ReadAllLines (Server.MapPath ("~ / TextFile1.txt")); fonctionne pour moi au lieu de ReadAllText (Server.MapPath ("~ / TextFile1.txt"));


@AbdulQayyum Heureux de vous aider :) pensez à le marquer comme réponse si c'est une solution pour vous



0
votes

Vous pouvez simplement faire ceci:

 string[] readText = File.ReadAllLines(path, Encoding.UTF8);
 string text = string.Empty; // or use StringBuilder;
 foreach (string s in readText)
 {
     text += $"\u2022 {s}" + System.Environment.NewLine;
 }

 txtBox1.Text = text;


0 commentaires