[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 583
  • Last Modified:

Problems with FileUpload Control

Hello,

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?
0
andyw27
Asked:
andyw27
1 Solution
 
dschauhan82Commented:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="AccessDataSource1" Width="148px" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblFileUpLoad" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</Columns>
</asp:GridView>

<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] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
</InsertParameters>
</asp:AccessDataSource>

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);
fileUpLoad.SaveAs(fullPath);
}

Regards
Digvijay Chauhan

0
 
quizwedgeCommented:
Information on the FileUpload control can be found at http://asp.net-tutorials.com/controls/file-upload-control/

Are you getting an error message with your code? Can you post your code so we can determine what is missing?
0
 
sybeCommented:
> ...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.


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now