Trouble with download link in webgrid

dallasf

New member
Joined
Oct 24, 2012
Messages
1
Programming Experience
Beginner
Hi,

I'm a beginner so go soft on me.

I have created a form which can upload a file to a my database via a stored procedure. The file uploads correctly and the file is located under my "files" directory.

I want to make that file accesible through my web grid, which I have. The file name is available and the download link is present.

However, when I go to click on the download link I recieve an error. Could not find file 'C:\LearningASP\Project\ConnXControlV2 3.7\1'.

Based on my code below I believe I had it all setup. I can see the error is telling me its looking for a file called 1, which is not there as its under the files directory.

I tried with mutliple links from other logged data and it always comes up with the requestid in the error. So, I believe its looking at the primary key when trying to download the file.

I'm confused in a big way. Please help.

<asp:GridView ID="gridClosedCalls" runat="server" AutoGenerateColumns="False" AllowPaging="True"
AllowSorting="True" DataKeyNames="RequestID" DataSourceID="closedCallsDataSourceGrid"
PageSize="8" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
EmptyDataText="No Applicable Data" SelectedRowStyle-BackColor="#99CCFF">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="RequestID" HeaderText="RequestID" ReadOnly="True" SortExpression="RequestID" />
<asp:BoundField DataField="Name" HeaderText="Client Name" SortExpression="Name" />
<asp:BoundField DataField="Priority" HeaderText="Priority" SortExpression="Priority" />
<asp:BoundField DataField="EmpName" HeaderText="Employee Name" SortExpression="EmpName" />
<asp:BoundField DataField="Module" HeaderText="Module" SortExpression="Module" />
<asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" />
<asp:BoundField DataField="ShortDescription" HeaderText="Short Description" SortExpression="ShortDescription" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="DateOfCall" HeaderText="Date Of Call" SortExpression="DateOfCall" />
<asp:BoundField DataField="ClosedDateOfCall" HeaderText="Closed Date Of Call" SortExpression="ClosedDateOfCall" />
<asp:BoundField DataField="FileName" HeaderText="FileName" />
<asp:TemplateField HeaderText="FilePath">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Select" Text="Select" />
</Columns>
<EmptyDataRowStyle CssClass="mGrid" />
<PagerStyle CssClass="pgr"></PagerStyle>
</asp:GridView>

Protected Sub lnkDownload_Click(sender As Object, e As EventArgs)
Dim lnkbtn As LinkButton = TryCast(sender, LinkButton)
Dim gvrow As GridViewRow = TryCast(lnkbtn.NamingContainer, GridViewRow)
Dim filePath As String = gridClosedCalls.DataKeys(gvrow.RowIndex).Value.ToString()
Response.ContentType = "image/jpg"
Response.AddHeader("Content-Disposition", "attachment;filename=""" & filePath & """")
Response.TransmitFile(Server.MapPath(filePath))
Response.[End]()
End Sub
End Class
 
Back
Top