Asked by:
view uploded files

Question
-
User639567535 posted
hey
i uploaded file in gridview and now i want to view these files i.e when any user click view button then this documnet view in broswer or open in other tab
code
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="false" EmptyDataText="no files uploaded">
<asp:HyperLink runat="server" ID="lnkButton" Text="View File" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
protected void FileUpload_Click(object sender, EventArgs e) { if (FileUploadControl.HasFile) { string strPath = Request.PhysicalApplicationPath + "~/DocFiles/" + FileUploadControl.FileName; FileUploadControl.SaveAs(strPath); lnkButton.NavigateUrl = "~/DocFiles/" + FileUploadControl.FileName; } }
but i find the error in link button
"The name 'lnkButton' does not exist in the current context "
where as i call the link button in grdiview (gridvie code above)
any help plzzz
Monday, September 23, 2013 4:17 AM
All replies
-
User-1516073966 posted
Hi
From your markup, the link button is inside the grid view, inorder to bind the saved document to the link button you need to do below:
You are saving/uploadig the file in shared location as per your file upload click code snippet, and save the path into database and retrieve this path and bind that to grid view.
Check out the link below:
Monday, September 23, 2013 5:36 AM -
User639567535 posted
i try this link but in this link
the code
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/")); List<ListItem> files = new List<ListItem>(); foreach (string filePath in filePaths) { files.Add(new ListItem(Path.GetFileName(filePath), filePath)); } GridView1.DataSource = files; GridView1.DataBind(); } }
in this link there is only download and delete option ....but i want to view document
Monday, September 23, 2013 12:27 PM -
User555306248 posted
Monday, September 23, 2013 11:56 PM -
User-933407369 posted
hi Bakhtawar ,
According to your description, I would suggest that you read this reference below:
Show images in asp.net page
http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html
Show a word document content in asp.net page
http://www.dotnetfunda.com/forums/show/3894/show-a-word-document-content-in-aspnet-page
I hope it helps you.
Sunday, October 6, 2013 10:59 PM