Solved

Problems with FileUpload Control

Posted on 2011-02-24
3
574 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
ID: 34968158
<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
ID: 34968171
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
ID: 34969772
> ...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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

23 Experts available now in Live!

Get 1:1 Help Now