Problems with FileUpload Control


I have gridview control that has within a template field.  This template field has a textbox within it.  At the moment this textbox accepts the file path, which is inputted manually.

I thought a more elegant solution would be to use the FileUpload control.  However I cannot get it work.

I’d like to try and accomplish the following.

1.      User browses to a file with the control
2.      Programmatically access both the full file path (including name and extension) and just filename (including extension)

Any ideas?
Who is Participating?
dschauhan82Connect With a Mentor Commented:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="AccessDataSource1" Width="148px" OnRowCommand="GridView1_RowCommand">
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:Label ID="lblFileUpLoad" runat="server"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />

<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/AccessDb.mdb"
SelectCommand="SELECT [ID], [Name] FROM [task]" DeleteCommand="DELETE FROM [task] WHERE [ID] = ?" InsertCommand="INSERT INTO [task] ([ID], [Name]) VALUES (?, ?)" UpdateCommand="UPDATE [task] SET [Name] = ? WHERE [ID] = ?">
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />

Code Behind File:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
if(GridView1.EditIndex == -1) return;
FileUpload fileUpLoad = GridView1.Rows[GridView1.EditIndex].FindControl("FileUpload1") as FileUpload;
string fileName = fileUpLoad.FileName;
string fullPath = Path.GetFullPath(fileName);

Digvijay Chauhan

Information on the FileUpload control can be found at

Are you getting an error message with your code? Can you post your code so we can determine what is missing?
> ...access both the full file path....

Some browsers (like Firefox)  do not specify the full path with fileupload (<input type="file">), but only the filename . So you won't have a cross-browser solution.

You need a signed script and/or ActiveX to get this fully supported.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.