Solved

Problems with FileUpload Control

Posted on 2011-02-24
3
573 Views
Last Modified: 2012-08-14
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
Comment
Question by:andyw27
3 Comments
 
LVL 4

Accepted Solution

by:
dschauhan82 earned 500 total points
Comment Utility
<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
 
LVL 14

Expert Comment

by:quizwedge
Comment Utility
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
 
LVL 28

Expert Comment

by:sybe
Comment Utility
> ...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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now