Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Actually i selected some text file using file upload box in asp.net...i wanna view that selected file text in another one textbox!!! how can i view select file content in textbox?
Posted

i find solution for this...
C#
write this coding on first page in some control like button...

        StreamReader r = new StreamReader(FileUpload1.FileContent);
        content=r.ReadToEnd();
        Session["filecontent"] = content;


then u wanna show ur selected file content in another page textboxt(In multimode) means
write this coding on second page:

Texbox1.Text = Session["files" ].ToString();


Happy Coding :)
 
Share this answer
 
v2
You can read uploaded file inputsteam into a stream object then using streamreader read and append lines in a string builder at the end of loop display string builder content in a texbox like this:

XML
<table>
          <tr>
              <td>
              </td>
              <td>
                  <asp:FileUpload ID="fileupload1" runat="server" />
              </td>
          </tr>
          <tr>
              <td>
              </td>
              <td>
                  <asp:Button ID="btnRead" runat="server" OnClick="btnRead_Click" Text="Read" />
              </td>
          </tr>
          <tr>
              <td valign="top">
                  Message of Created Text file :
              </td>
              <td>
                  <asp:TextBox ID="textBoxContents" runat="server" TabIndex="0" Height="380px" TextMode="MultiLine"
                      Width="367px"></asp:TextBox>
              </td>
          </tr>
      </table>




protected void btnRead_Click(object sender, EventArgs e)
        {
            string path = fileupload1.PostedFile.FileName;
            if (!string.IsNullOrEmpty(path))
            {

                Stream theStream = fileupload1.PostedFile.InputStream;
                StringBuilder strbuild = new StringBuilder();
                using (StreamReader sr = new StreamReader(theStream))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        strbuild.Append(line);
                        strbuild.AppendLine();
                    }
                }
               
                textBoxContents.Text = strbuild.ToString();
            }

           
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900