Hi, you can save the upload file path to a hidden filed, and then get it with LinkButton click event. With the following example, after choosing the upload file and clicking “Upload” button, the file will be uploaded to server and the file path will be saved
to the hidden field. Then please click the LinkButton, it will get the file path from the hidden field, find the file and show its content to Label “lblResult”.
starmgm
Member
58 Points
53 Posts
how to take the file uploaded path and use it for linkbutton using javascript?
Feb 19, 2012 08:41 PM|LINK
how to take the file uploaded path and use it for linkbutton using javascript??? may anyone help
A1ien51
All-Star
29935 Points
5821 Posts
Re: how to take the file uploaded path and use it for linkbutton using javascript?
Feb 19, 2012 10:24 PM|LINK
What do you actually want to do? Your question makes no sense.
Eric
Danny Gokey
Member
290 Points
56 Posts
Re: how to take the file uploaded path and use it for linkbutton using javascript?
Feb 20, 2012 01:51 AM|LINK
Hi
I am guessing you mean to set the file uploaded path as one linkbutton, so that when you click the linkbutton, you can easily find
the upload file.
Do you think so?
Ruchira
All-Star
42943 Points
7024 Posts
MVP
Re: how to take the file uploaded path and use it for linkbutton using javascript?
Feb 20, 2012 07:56 AM|LINK
Hi,
If you mean the path value, you can first save it in a hidden field and then access it in the client side.
In javascripts, you can access that value using the below code.
document.getElementById('<%=HiddenFieldID.ClientID%>').value
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.starmgm
Member
58 Points
53 Posts
Re: how to take the file uploaded path and use it for linkbutton using javascript?
Feb 20, 2012 08:04 AM|LINK
@Danny Gokey yes that is it
sunilgurjar
Contributor
2252 Points
478 Posts
Re: how to take the file uploaded path and use it for linkbutton using javascript?
Feb 20, 2012 08:11 AM|LINK
read my blog
http://sunilgurjar.blogspot.com/
Allen Li - M...
Star
10411 Points
1196 Posts
Re: how to take the file uploaded path and use it for linkbutton using javascript?
Feb 21, 2012 08:06 AM|LINK
Hi, you can save the upload file path to a hidden filed, and then get it with LinkButton click event. With the following example, after choosing the upload file and clicking “Upload” button, the file will be uploaded to server and the file path will be saved to the hidden field. Then please click the LinkButton, it will get the file path from the hidden field, find the file and show its content to Label “lblResult”.
Markup:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="FUAttachContract" runat="server" /> <asp:Button ID="ButtUploadCntract" runat="server" Height="22px" Text="Upload" Width="67px" onclick="ButtUploadCntract_Click" /> <asp:HiddenField ID="HiddenField1" runat="server" /> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">ShowContent</asp:LinkButton> <br /> <asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>C# codes:
protected void Page_Load(object sender, EventArgs e) { } protected void LinkButton1_Click(object sender, EventArgs e) { string content = showTxtContent(this.HiddenField1.Value); this.lblResult.Text = content; } private string showTxtContent(string path) { string instream = ""; string getstream = ""; if (File.Exists(path)) { StreamReader sr = new StreamReader(path, Encoding.GetEncoding("utf-8")); instream = sr.ReadLine(); while (instream != null) { getstream += instream; instream = sr.ReadLine(); } return getstream; } else { return "file doesn't exist"; } } protected void ButtUploadCntract_Click(object sender, EventArgs e) { string path = AppDomain.CurrentDomain.BaseDirectory + "\\" + this.FUAttachContract.FileName; this.FUAttachContract.SaveAs(path); this.HiddenField1.Value = path; }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework