Reputation: 9661
I create a list with upload files (just .txt files),
blListDocs.Items.Clear();
string pn = Server.MapPath("../Uploads/Data");
string pathToWebAppRoot = Request.ApplicationPath;
string pathToFolder = "/Uploads/Data/";
string urlPath = pathToWebAppRoot + pathToFolder;
String[] fileList = Directory.GetFiles(pn);
for (int i = 0; i < fileList.Length - 1; i++)
{
ListItem li = new ListItem();
li.Text = Path.GetFileName(fileList[i]);
li.Value = urlPath + li.Text;
blListDocs.Items.Add(li);
}
Now, when I click one item link, the file's content is opening in another Web Page, but I'd like to read clicked file's content in control
<asp:TextBox ID="txtReadDocs" runat="server" TextMode="MultiLine" Rows="4"></asp:TextBox>
Thank You so much!!
Upvotes: 1
Views: 509
Reputation: 10276
If you want a server side implementation link the url of your page to the same page and append a querystring parameter specifying which text file you want...then you have full access to read the text file and stuff it into your control. Otherwise use the jQuery answer listed by @ChaosPandion
Upvotes: 1
Reputation: 78282
function onLinkClick(link) {
$.get(link.href, '', function(data) {
$("input[id*=txtReadDocs]").val(data);
}
}
Upvotes: 1