473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File Upload from within datalist

Hello-
I'm having a problem doing a file upload from within the edit function
of a datalist. I have a simple file upload that works on a standard
..net page:
<td width="53"><input id="inpFileUp" type="file" runat="Server"
/>&nbsp;</td>
<asp:Button id="Button1" onclick="Button_Click2" Runat="Server"
Text="Upload File!"></asp:Button>

And this is the function to upload the file:

Sub Button_Click2( s As Object, e As EventArgs )
Dim fileName As String
Dim saveAs As String
Dim resultsText as String
fileName = inpFileUp.PostedFile.FileName
fileName = Path.GetFileName(fileName)
saveAs = "C:\inetpub\wwwroot\images\" & fileName
inpFileUp.PostedFile.SaveAs( saveAs )
resultsText = "Image file: "
lblUploadResults.Text = resultsText
lblUploadFile.Text = fileName
inpFileUp.Visible=False
Button1.Visible=False
End Sub

This all works fine. It doesn't, of course, work from within the edit
item template of a datalist. I get this error:
"Name 'inpFileUp' is not declared"
I can't seem to use "find control" either, sense I'm calling it from a
button click.

If I try to skip the actual upload until I'm in the "update item"
function, I get errors such as :
System.Web.UI.Control cannot be converted to System.Web.HttpPostedFile

So anyhow, the idea is that I have a datalist with a number of
records, and I'd like to be able to upload a file from within the edit
item template of one of these items.

Any ideas?

Thank you!

David
Nov 18 '05 #1
3 3766
The easiest way to Debug these type of Problems is to Disable SmartNavigation and then to use the View Source function in your Browser. Then search for the code where the 'inpFileUp' is declared. If you see a Prefix then you will know that inside the ItemBound Event etc in a DataGrid you would have to use the FindControl Method and then pass the ClientID to the function. Let me know if you need a sample.

Regards,

Trevor Benedict R
Nov 18 '05 #2
So I figured it out (with help from 4guysfromrolla.com), so hopefully
this will help someone else:

this is what I did:
Dim saveAs As String
Dim fileName As String
Dim inpFileUp As New HtmlInputFile()
inpFileUp = CType(e.Item.FindControl("inpFileUp"),
HtmlInputFile)
fileName = inpFileUp.PostedFile.FileName
fileName = Path.GetFileName(fileName)
saveAs = "C:\inetpub\wwwroot\images\" & fileName
' Response.Write(saveAs)
inpFileUp.PostedFile.SaveAs( saveAs )

And then I put this in the "Update Function" rather than keeping it in
a separate button click.

Works well now.

David

dw*@auto-graphics.com (David Kenneally) wrote in message news:<57**************************@posting.google. com>...
Hello-
I'm having a problem doing a file upload from within the edit function
of a datalist. I have a simple file upload that works on a standard
.net page:
<td width="53"><input id="inpFileUp" type="file" runat="Server"
/>&nbsp;</td>
<asp:Button id="Button1" onclick="Button_Click2" Runat="Server"
Text="Upload File!"></asp:Button>

And this is the function to upload the file:

Sub Button_Click2( s As Object, e As EventArgs )
Dim fileName As String
Dim saveAs As String
Dim resultsText as String
fileName = inpFileUp.PostedFile.FileName
fileName = Path.GetFileName(fileName)
saveAs = "C:\inetpub\wwwroot\images\" & fileName
inpFileUp.PostedFile.SaveAs( saveAs )
resultsText = "Image file: "
lblUploadResults.Text = resultsText
lblUploadFile.Text = fileName
inpFileUp.Visible=False
Button1.Visible=False
End Sub

This all works fine. It doesn't, of course, work from within the edit
item template of a datalist. I get this error:
"Name 'inpFileUp' is not declared"
I can't seem to use "find control" either, sense I'm calling it from a
button click.

If I try to skip the actual upload until I'm in the "update item"
function, I get errors such as :
System.Web.UI.Control cannot be converted to System.Web.HttpPostedFile

So anyhow, the idea is that I have a datalist with a number of
records, and I'd like to be able to upload a file from within the edit
item template of one of these items.

Any ideas?

Thank you!

David

Nov 18 '05 #3
Al
You just made my day, THANK YOU!!

From http://www.developmentnow.com/g/8_20...n-datalist.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: fchiausa | last post by:
Hello, I'm having a hard time trying to manage an input type file in a datalist here is my aspx code : <INPUT type="file" id="InputImageFile2" runat="server"><br> <input type="submit"...
1
by: pete K | last post by:
Is it possible in asp.net to have a datalist in the itemtemplate of another datalist? For example: <asp:datalist id="MyList" runat="server"> <ItemTemplate> <table border="0" width="300">...
1
by: Doug | last post by:
The html below shows DataList "DiscountList" nested within DataList "EventItemList". DiscountList contains a Label control. I'm trying to find the label, using FindControl, during...
9
by: jjack100 | last post by:
I want to set the text value of a label that is within a datalist in the codebehind. Does this have to be done in the databound event? Simplified example: <asp:DataList id="dlItem"...
0
by: Jameel | last post by:
I am facing 2 problems: 1. I have files uploaded to the server and have the relevant information in database, and now I want to pull the image name and path from database and have the images...
0
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView (databound using another ObjectDataSource2 contained in...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
1
by: Sam | last post by:
Hi all, We have an old web application written in java and we want to convert this application to .net. this app stores straight html content forms in our database. These forms then get loaded...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.